|
|
|
|
IF object_id('dbo.PCalcDynamicEmpComm','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PCalcDynamicEmpComm
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE dbo.PCalcDynamicEmpComm
|
|
|
|
|
(
|
|
|
|
|
@CompId BIGINT,
|
|
|
|
|
@EmpId BIGINT
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
--DECLARE @EmpId BIGINT
|
|
|
|
|
--DECLARE @CompId BIGINT
|
|
|
|
|
|
|
|
|
|
--SELECT @EmpId = 0
|
|
|
|
|
--SELECT @CompId = FCompId FROM #Company
|
|
|
|
|
|
|
|
|
|
--Ա<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>,ֻ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⷽ<EFBFBD><EFBFBD>
|
|
|
|
|
CREATE TABLE #EmployeeScheme
|
|
|
|
|
(
|
|
|
|
|
FEmpId BIGINT,
|
|
|
|
|
FItemSchemeId BIGINT, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemTypeKey VARCHAR(20) --<EFBFBD>ۼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
)
|
|
|
|
|
IF @EmpId != 0
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #EmployeeScheme(FEmpId,FItemSchemeId,FItemTypeKey)
|
|
|
|
|
SELECT @EmpId,A.FId,CASE WHEN A.FAcum = 1 THEN 'ItemType' ELSE 'ItemKind' END
|
|
|
|
|
FROM TEmployeeCommScheme AS S,TItemCommSchemeMaster AS A
|
|
|
|
|
WHERE S.FCompId = @CompId
|
|
|
|
|
AND S.FCompId = A.FCompId
|
|
|
|
|
AND A.FAcum IN(1,2)
|
|
|
|
|
AND S.FItemSchemeId = A.FId
|
|
|
|
|
AND S.FEmpId = @EmpId
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
IF object_id('tempdb..#Employee') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #EmployeeScheme(FEmpId,FItemSchemeId,FItemTypeKey)
|
|
|
|
|
SELECT E.FEmpId,A.FId,CASE WHEN A.FAcum = 1 THEN 'ItemType' ELSE 'ItemKind' END
|
|
|
|
|
FROM #Employee AS E,TEmployeeCommScheme AS S,TItemCommSchemeMaster AS A
|
|
|
|
|
WHERE S.FCompId = @CompId
|
|
|
|
|
AND A.FCompID = S.FCompId
|
|
|
|
|
AND A.FAcum IN(1,2)
|
|
|
|
|
AND S.FItemSchemeId = A.FId
|
|
|
|
|
AND E.FEmpID = S.FEmpId
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #EmployeeScheme(FEmpId,FItemSchemeId,FItemTypeKey)
|
|
|
|
|
SELECT E.FEmpId,A.FId,CASE WHEN A.FAcum = 1 THEN 'ItemType' ELSE 'ItemKind' END
|
|
|
|
|
FROM TEmployeeSub AS E,TEmployeeCommScheme AS S,TItemCommSchemeMaster AS A
|
|
|
|
|
WHERE E.FCompId = @CompId
|
|
|
|
|
AND E.FCompID = S.FCompId
|
|
|
|
|
AND E.FCompId = A.FCompId
|
|
|
|
|
AND A.FAcum IN(1,2)
|
|
|
|
|
AND S.FItemSchemeId = A.FId
|
|
|
|
|
AND E.FEmpId = S.FEmpId
|
|
|
|
|
END
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CREATE TABLE #SchemeSection
|
|
|
|
|
(
|
|
|
|
|
FSchemeId BIGINT NOT NULL,
|
|
|
|
|
FSectionId BIGINT NOT NULL,
|
|
|
|
|
FSequence INT NOT NULL,
|
|
|
|
|
FItemTypeId BIGINT,
|
|
|
|
|
FDispatchMode BIGINT,
|
|
|
|
|
FSectionMode INT,
|
|
|
|
|
FFromValue DECIMAL(18,6) NOT NULL,
|
|
|
|
|
FToValue DECIMAL(18,6) NOT NULL,
|
|
|
|
|
FAloneCalc BIT NOT NULL
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ȡ<EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
INSERT #SchemeSection(FSchemeId,FSectionId,FSequence,FItemTypeId,FDispatchMode,FSectionMode,FFromValue,FToValue,FAloneCalc)
|
|
|
|
|
SELECT FMasterId,FId,FSequence,FItemTypeId,FDispatchMode,FSectionMode,FFromValue,FToValue,FAloneCalc
|
|
|
|
|
FROM TItemCommSchemeSection AS A WITH(NOLOCK)
|
|
|
|
|
WHERE EXISTS (SELECT 1 FROM #EmployeeScheme AS E WHERE E.FItemSchemeId = A.FMasterId)
|
|
|
|
|
|
|
|
|
|
IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
--Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CREATE table #PerfDetailAcum
|
|
|
|
|
(
|
|
|
|
|
FEmpId BIGINT NOT NULL, --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
FItemTypeKey VARCHAR(20) NOT NULL,--ItemType <EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ItemKind <EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemTypeId BIGINT NOT NULL, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FDispatchMode BIGINT, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FAmt DECIMAL(18,6) NOT NULL, --Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FActAmt DECIMAL(18,6) NOT NULL, --ʵ<EFBFBD>ն<EFBFBD>
|
|
|
|
|
FPerf DECIMAL(18,6) NOT NULL, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FDedCostPerf DECIMAL(18,6) NOT NULL, --<EFBFBD>۳ɱ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FQuantity DECIMAL(18,6) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ȡԱ<EFBFBD><EFBFBD><EFBFBD>ۼ<EFBFBD>
|
|
|
|
|
INSERT #PerfDetailAcum(FEmpId,FItemTypeKey,FItemTypeId,FDispatchMode,FAmt,FActAmt,FPerf,FDedCostPerf,FQuantity)
|
|
|
|
|
SELECT A.FEmpId,'ItemType',A.FItemTypeId,A.FDispatchMode,SUM(A.FAmt),SUM(FActAmt),SUM(A.FPerf),SUM(FDedCostPerf),SUM(A.FQuantity)
|
|
|
|
|
FROM #EmpPerfDetail AS A WITH(NOLOCK)
|
|
|
|
|
-- AND A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
GROUP BY A.FEmpId,A.FItemTypeId,A.FDispatchMode
|
|
|
|
|
|
|
|
|
|
IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF EXISTS(SELECT 1 FROM #EmployeeScheme WHERE FItemTypeKey = 'ItemKind') --<EFBFBD>а<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۼƵ<EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #PerfDetailAcum(FEmpId,FItemTypeKey,FItemTypeId,FDispatchMode,FAmt,FActAmt,FPerf,FDedCostPerf,FQuantity)
|
|
|
|
|
SELECT A.FEmpId,'ItemKind',S.FParentId,A.FDispatchMode,SUM(A.FAmt),SUM(FActAmt),SUM(A.FPerf),SUM(FDedCostPerf),SUM(A.FQuantity)
|
|
|
|
|
FROM #PerfDetailAcum AS A WITH(NOLOCK),TBasicType AS S WITH(NOLOCK)
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
AND A.FCompId = @CompId
|
|
|
|
|
AND S.FId = A.FItemTypeId
|
|
|
|
|
GROUP BY A.FEmpId,S.FParentId,A.FDispatchMode
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF EXISTS(SELECT 1 FROM #SchemeSection WHERE FItemTypeId = 1) --ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #PerfDetailAcum(FEmpId,FItemTypeKey,FItemTypeId,FDispatchMode,FAmt,FActAmt,FPerf,FDedCostPerf,FQuantity)
|
|
|
|
|
SELECT A.FEmpId,FItemTypeKey,1,A.FDispatchMode,SUM(A.FAmt),SUM(FActAmt),SUM(A.FPerf),SUM(FDedCostPerf),SUM(A.FQuantity)
|
|
|
|
|
FROM #PerfDetailAcum AS A WITH(NOLOCK)
|
|
|
|
|
GROUP BY A.FEmpId,FItemTypeKey,A.FDispatchMode
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF EXISTS(SELECT 1 FROM #SchemeSection WHERE FDispatchMode = 1)
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT #PerfDetailAcum(FEmpId,FItemTypeKey,FItemTypeId,FDispatchMode,FAmt,FActAmt,FPerf,FDedCostPerf,FQuantity)
|
|
|
|
|
SELECT A.FEmpId,FItemTypeKey,FItemTypeId,1,SUM(A.FAmt),SUM(FActAmt),SUM(A.FPerf),SUM(FDedCostPerf),SUM(A.FQuantity)
|
|
|
|
|
FROM #PerfDetailAcum AS A WITH(NOLOCK)
|
|
|
|
|
GROUP BY A.FEmpId,FItemTypeKey,FItemTypeId
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
declare @itemtypes table
|
|
|
|
|
(
|
|
|
|
|
accumu_item_type varchar(5),
|
|
|
|
|
join_item_type varchar(5)
|
|
|
|
|
)
|
|
|
|
|
declare @actiontypes table
|
|
|
|
|
(
|
|
|
|
|
accumu_action_type varchar(5),
|
|
|
|
|
join_action_type varchar(5)
|
|
|
|
|
)
|
|
|
|
|
declare @goodstypes table
|
|
|
|
|
(
|
|
|
|
|
accumu_goods_type varchar(5),
|
|
|
|
|
join_goods_type varchar(5)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ʼѭ<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @CurrEmpId BIGINT --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
DECLARE @SchemeId BIGINT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Id
|
|
|
|
|
DECLARE @SectionId BIGINT --<EFBFBD>ֶ<EFBFBD>Id
|
|
|
|
|
DECLARE @DispatchMode BIGINT --ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
DECLARE @SectionMode INT --<EFBFBD>ֶη<EFBFBD>ʽ
|
|
|
|
|
DECLARE @ItemTypeKey VARCHAR(20) --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>key
|
|
|
|
|
DECLARE @ItemTypeId BIGINT --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Id
|
|
|
|
|
DECLARE @FromValue DECIMAL(18,6) --<EFBFBD><EFBFBD>ʼֵ
|
|
|
|
|
DECLARE @ToValue DECIMAL(18,6) --<EFBFBD><EFBFBD>ֵֹ
|
|
|
|
|
DECLARE @Index INT --<EFBFBD>ֶα<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @Count INT --<EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
DECLARE @Amt DECIMAL(18,6)
|
|
|
|
|
DECLARE @ActAmt DECIMAL(18,6)
|
|
|
|
|
DECLARE @Perf DECIMAL(18,6)
|
|
|
|
|
DECLARE @DedCostPerf DECIMAL(18,6)
|
|
|
|
|
|
|
|
|
|
DECLARE @LastSectionId BIGINT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>ķֶ<EFBFBD>ID
|
|
|
|
|
DECLARE @LastItemTypeId BIGINT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @LastDispatchMode BIGINT --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
DECLARE @LastPerf DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @LastActAmt DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>ʵ<EFBFBD>ն<EFBFBD>
|
|
|
|
|
DECLARE @LastAmt DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @LastDedCostPerf DECIMAL(18,6) --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>εĿ۳ɱ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE EmpCur CURSOR FOR
|
|
|
|
|
SELECT FEmpId,FItemSchemeId,FItemTypeKey
|
|
|
|
|
FROM #EmployeeScheme AS E
|
|
|
|
|
WHERE EXISTS(SELECT 1 FROM #PerfDetailAcum AS A WHERE A.FEmpId = E.FEmpId)
|
|
|
|
|
|
|
|
|
|
OPEN EmpCur
|
|
|
|
|
FETCH EmpCur INTO @CurrEmpId,@SchemeId,@ItemTypeKey
|
|
|
|
|
WHILE @@FETCH_STATUS = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
print @CurrEmpId
|
|
|
|
|
SELECT @LastSectionId = 0,
|
|
|
|
|
@LastItemTypeId = -1,
|
|
|
|
|
@LastDispatchMode = -1,
|
|
|
|
|
@Amt = 0,
|
|
|
|
|
@ActAmt = 0,
|
|
|
|
|
@Perf = 0,
|
|
|
|
|
@DedCostPerf = 0
|
|
|
|
|
|
|
|
|
|
SELECT @Count = COUNT(1)
|
|
|
|
|
FROM #SchemeSection
|
|
|
|
|
WHERE FSchemeId = @SchemeId
|
|
|
|
|
|
|
|
|
|
SELECT @Index = @Count
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>
|
|
|
|
|
WHILE @Index > 0
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @SectionId = FSectionId,
|
|
|
|
|
@ItemTypeId = FItemTypeId,
|
|
|
|
|
@DispatchMode = FDispatchMode,
|
|
|
|
|
@SectionMode = FSectionMode,
|
|
|
|
|
@FromValue = FFromValue,
|
|
|
|
|
@ToValue = FToValue
|
|
|
|
|
FROM #SchemeSection
|
|
|
|
|
WHERE FSchemeId = @SchemeId
|
|
|
|
|
AND FSequence = @Index
|
|
|
|
|
|
|
|
|
|
PRINT 'SectoinId=' + CAST(@SectionId AS VARCHAR(20) )
|
|
|
|
|
+ ',ItemTypeId='+ CAST(@ItemTypeId AS VARCHAR(20))
|
|
|
|
|
+ ',DispatchMode='+ CAST(@DispatchMode AS VARCHAR(20))
|
|
|
|
|
+ ',SectionMode='+ CAST(@SectionMode AS VARCHAR(20))
|
|
|
|
|
+ ',FromValue='+ CAST(@FromValue AS VARCHAR(20))
|
|
|
|
|
+ ',ToValue='+ CAST(@ToValue AS VARCHAR(20))
|
|
|
|
|
|
|
|
|
|
IF @LastItemTypeId != @ItemTypeId OR @LastDispatchMode != @DispatchMode
|
|
|
|
|
BEGIN
|
|
|
|
|
PRINT 'SELECT'
|
|
|
|
|
SELECT @Amt = FAmt,
|
|
|
|
|
@ActAmt = FActAmt,
|
|
|
|
|
@Perf = FPerf,
|
|
|
|
|
@DedCostPerf = FDedCostPerf
|
|
|
|
|
FROM #PerfDetailAcum
|
|
|
|
|
WHERE FEmpId = @CurrEmpId
|
|
|
|
|
AND FItemTypeKey = @ItemTypeKey
|
|
|
|
|
AND FItemTypeId = @ItemTypeId
|
|
|
|
|
AND FDispatchMode = @DispatchMode
|
|
|
|
|
|
|
|
|
|
-- SELECT * FROM #PerfDetailAcum WHERE FEmpId = @CurrEmpId AND FItemTypeId = @ItemTypeId
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
PRINT '@Amt=' + CAST(@Amt AS VARCHAR(20) )
|
|
|
|
|
+ ',@ActAmt='+ CAST(@ActAmt AS VARCHAR(20))
|
|
|
|
|
+ ',@@Perf='+ CAST(@Perf AS VARCHAR(20))
|
|
|
|
|
+ ',@@DedCostPerf='+ CAST(@DedCostPerf AS VARCHAR(20))
|
|
|
|
|
|
|
|
|
|
DECLARE @Value DECIMAL(18,6)
|
|
|
|
|
|
|
|
|
|
IF @SectionMode = 2 --Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @Value = @Amt
|
|
|
|
|
END
|
|
|
|
|
ELSE IF @SectionMode = 3 --ʵ<EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @Value = @ActAmt
|
|
|
|
|
END
|
|
|
|
|
ELSE IF @SectionMode = 4 --ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @Value = @Perf
|
|
|
|
|
END
|
|
|
|
|
ELSE IF @SectionMode = 5 --<EFBFBD>۳ɱ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @Value = @DedCostPerf
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT @Value = 0
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF @Value >= @FromValue AND @Value < @ToValue
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
|
|
--ƥ<EFBFBD>䵽<EFBFBD><EFBFBD>
|
|
|
|
|
--<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>ʽ
|
|
|
|
|
--
|
|
|
|
|
IF EXISTS(SELECT 1 FROM TItemCommSchemeDetail AS A WITH(NOLOCK) WHERE FParentId = @SectionId AND A.FItemId = 0)
|
|
|
|
|
BEGIN
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FBaseCommMode = B.FCommMode,
|
|
|
|
|
A.FBaseCommValue = B.FCommValue
|
|
|
|
|
FROM #EmpPerfDetail AS A,TItemCommSchemeDetail AS B WITH(NOLOCK)
|
|
|
|
|
WHERE B.FPayTypeId = 0
|
|
|
|
|
AND A.FWorkType = B.FWorkType
|
|
|
|
|
AND A.FDispatchMode = B.FDispatchMode
|
|
|
|
|
AND B.FParentId = @SectionId
|
|
|
|
|
AND A.FCategory = 'Item'
|
|
|
|
|
END
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FBaseCommMode = B.FCommMode,
|
|
|
|
|
A.FBaseCommValue = B.FCommValue
|
|
|
|
|
FROM #EmpPerfDetail AS A,TItemCommSchemeDetail AS B WITH(NOLOCK)
|
|
|
|
|
WHERE B.FPayTypeId = 0
|
|
|
|
|
AND A.FItemId = B.FItemId
|
|
|
|
|
AND A.FWorkType = B.FWorkType
|
|
|
|
|
AND A.FDispatchMode = B.FDispatchMode
|
|
|
|
|
AND B.FParentId = @SectionId
|
|
|
|
|
AND A.FCategory = 'Item'
|
|
|
|
|
|
|
|
|
|
BREAK;
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
SELECT @Index = @Index - 1
|
|
|
|
|
END
|
|
|
|
|
FETCH EmpCur INTO @CurrEmpId,@SchemeId,@ItemTypeKey
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
CLOSE EmpCur
|
|
|
|
|
DEALLOCATE EmpCur
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FBaseComm = CASE A.FBaseCommMode
|
|
|
|
|
WHEN 1 THEN A.FBaseCommValue * A.FSplitQuantity * A.FShareRate
|
|
|
|
|
WHEN 2 THEN A.FBaseCommValue * A.FAmt
|
|
|
|
|
WHEN 3 THEN A.FBaseCommValue * A.FActAmt
|
|
|
|
|
WHEN 4 THEN A.FBaseCommValue * A.FPerf
|
|
|
|
|
WHEN 5 THEN A.FBaseCommValue * A.FDedCostPerf
|
|
|
|
|
WHEN 6 THEN A.FBaseCommValue * A.FPerf * A.FActRate --ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ն<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
WHEN 7 THEN A.FBaseCommValue * A.FOrigPrice
|
|
|
|
|
ELSE 0 END
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
WHERE A.FCategory = 'Item'
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FComm = A.FBaseComm + A.FExtraComm
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
WHERE A.FCategory = 'Item'
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptWageReport01','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptWageReport01
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE PRptWageReport01
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @CompanyStr VARCHAR(8000)
|
|
|
|
|
DECLARE @FromDate CHAR(10)
|
|
|
|
|
DECLARE @ToDate CHAR(10)
|
|
|
|
|
DECLARE @IncChild CHAR
|
|
|
|
|
DECLARE @CashierId BIGINT
|
|
|
|
|
DECLARE @DeptId BIGINT
|
|
|
|
|
DECLARE @AllCompany BIT
|
|
|
|
|
DECLARE @PayTypeNo VARCHAR(1000)
|
|
|
|
|
DECLARE @ItemNo VARCHAR(1000)
|
|
|
|
|
DECLARE @DeptNo VARCHAR(1000)
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT @CompanyStr = dbo.FNGetParamValue(@IParam,'Company')
|
|
|
|
|
SELECT @FromDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'FromDate'),23)
|
|
|
|
|
SELECT @ToDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'ToDate'),23)
|
|
|
|
|
SELECT @PayTypeNo = ISNULL(dbo.FNGetParamValue(@IParam,'PayTypeNo'),'')
|
|
|
|
|
SELECT @ItemNo = ISNULL(dbo.FNGetParamValue(@IParam,'ItemNo'),'')
|
|
|
|
|
SELECT @DeptNo = ISNULL(dbo.FNGetParamValue(@IParam,'DeptNo'),'')
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@ToDate,'') = '' OR ISNULL(@FromDate,'') = '' OR @FromDate > @ToDate
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT,
|
|
|
|
|
FCompNo VARCHAR(20)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT #Company
|
|
|
|
|
SELECT A.FId,A.FNo
|
|
|
|
|
FROM TCompany AS A WITH(NOLOCK), dbo.FNStrSplit(@CompanyStr) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = FCompId FROM #Company
|
|
|
|
|
|
|
|
|
|
IF @DeptNo = '' OR @DeptNo = '*'
|
|
|
|
|
BEGIN
|
|
|
|
|
SET @DeptId = 0
|
|
|
|
|
END
|
|
|
|
|
SELECT @DeptId = FId FROM TBasicType WITH(NOLOCK) WHERE FKey = 'Department' AND FNo = @DeptNo
|
|
|
|
|
|
|
|
|
|
DECLARE @PayTypeIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FPayTypeId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @ItemIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FItemId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @CourseIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FCourseId BIGINT
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF @PayTypeNo != ''
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT @PayTypeIds(FPayTypeId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TPayAccount AS A WITH(NOLOCK), dbo.FNStrSplit(@PayTypeNo) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF @ItemNo != ''
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT @ItemIds(FItemId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TItem AS A WITH(NOLOCK), dbo.FNStrSplit(@ItemNo) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
|
|
|
|
|
INSERT @CourseIds(FCourseId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TCourse AS A WITH(NOLOCK) ,@ItemIds AS B
|
|
|
|
|
WHERE A.FItemId = B.FItemId
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SET @AllCompany = 0
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#Company <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PGenerateEmpPerf @AllCompany,@FromDate,@ToDate
|
|
|
|
|
|
|
|
|
|
/* SELECT A.FId AS FEmpId , A.FNo FEmpNo, A.FName AS FEmpName, CAST(A.FPosId AS VARCHAR(20)) AS FPosId
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK)
|
|
|
|
|
INNER JOIN #Company AS C on c.FCompId = a.FCompId
|
|
|
|
|
|
|
|
|
|
UNION ALL */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT A.FId AS FEmpId, A.FNo AS FEmpNo,A.FName AS FEmpName, CAST(A.FPosId AS VARCHAR(20)) AS PosId
|
|
|
|
|
INTO #Employee
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK)
|
|
|
|
|
INNER JOIN TEmployeeSub AS B ON B.FEmpId = A.FId
|
|
|
|
|
INNER JOIN #Company AS C ON C.FCompId = B.FCompId
|
|
|
|
|
WHERE (@DeptId = 0 OR A.FDeptId = @DeptId)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>浽<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.* INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A WITH(NOLOCK),#Employee AS E
|
|
|
|
|
WHERE A.FIsExpired = 0
|
|
|
|
|
AND A.FEmpId = E.FEmpId
|
|
|
|
|
AND A.FCompId = @CompId
|
|
|
|
|
AND A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,0
|
|
|
|
|
|
|
|
|
|
SELECT E.FEmpId AS EmpId, E.FEmpNo AS EmpNo, A.FCategory AS Category, FBillNo AS BillNo,FBillDetailId AS BillDetailId,
|
|
|
|
|
CONVERT(varchar(20),A.FBillTime, 120) AS BillTime,FWorkDate AS WorkDate, FWorkType AS WorkType,FDispatchMode AS DispatchMode, S.FName AS DispatchModeName,
|
|
|
|
|
FItemNo AS ItemNo, FItemNo + '-' + FItemName AS ItemName, FQuantity AS Quantity, P.FName AS PayTypeName, A.FPayTypeId AS PayTypeId,
|
|
|
|
|
FAmt AS PayAmt, FPerf AS Perf,FComm AS Comm,FDedCostPerf AS DedCostPerf,
|
|
|
|
|
CASE WHEN A.FCategory = 'Item' THEN S2.FName WHEN A.FCategory = 'Goods' THEN S4.FName ELSE S3.FName END AS WorkTypeName,
|
|
|
|
|
A.FMemNo AS MemNo,ISNULL(A.FCustName,M.FName) AS CustName, A.FCardNo AS CardNo, CASE WHEN ISNULL(FCustGender,M.FGender) = 1 THEN '<EFBFBD><EFBFBD>' ELSE 'Ů' END AS CustGender
|
|
|
|
|
INTO #PerfDetail
|
|
|
|
|
FROM #Employee AS E, #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TBasicType AS S WITH(NOLOCK) ON S.FKey = 'ServeDispatchMode' AND S.FId = A.FDispatchMode
|
|
|
|
|
LEFT JOIN TBasicType AS S2 WITH(NOLOCK) ON S2.FKey = 'ServeWorkType' AND S2.FId = A.FWorkType AND A.FCategory = 'Item'
|
|
|
|
|
LEFT JOIN TBasicType AS S3 WITH(NOLOCK) ON S3.FKey = 'MemSaleWorkType' AND S3.FId = A.FWorkType AND A.FCategory IN('CardSale','CardRchg','CourseSale','CoursePackSale')
|
|
|
|
|
LEFT JOIN TBasicType AS S4 WITH(NOLOCK) ON S4.FKey = 'GoodsSaleWorkType' AND S4.FId = A.FWorkType AND A.FCategory IN('Goods')
|
|
|
|
|
LEFT JOIN TMember AS M WITH(NOLOCK) ON A.FMemId = M.FMemId
|
|
|
|
|
LEFT JOIN TPayAccount AS P ON P.FId = A.FPayTypeId
|
|
|
|
|
WHERE E.FEmpId = A.FEmpId
|
|
|
|
|
AND (@PayTypeNo = '' OR A.FPayTypeId IN(SELECT FPayTypeId FROM @PayTypeIds))
|
|
|
|
|
AND (@ItemNo = '' OR (A.FCategory = 'Item' AND A.FItemId IN(SELECT FItemId FROM @ItemIds) )
|
|
|
|
|
OR (A.FCategory = 'CourseSale' AND A.FItemId IN(SELECT FCourseId FROM @CourseIds) ))
|
|
|
|
|
|
|
|
|
|
ORDER BY A.FEmpId,CASE WHEN A.FCategory IN('CardSale','CardRchg') THEN 1 WHEN A.FCategory IN( 'CourseSale','CoursePackSale') THEN 2
|
|
|
|
|
WHEN A.FCategory = 'Goods' THEN 3 WHEN A.FCategory = 'Item' THEN 4 ELSE 5 END
|
|
|
|
|
,FBillTime, FBillNo,FBillDetailId,FWorkType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT FEmpNo AS EmpNo, FEmpName AS EmpName
|
|
|
|
|
FROM #Employee AS B
|
|
|
|
|
WHERE EXISTS(SELECT TOP 1 1 FROM #PerfDetail AS A WHERE A.EmpId = B.FEmpId)
|
|
|
|
|
ORDER BY FEmpNo
|
|
|
|
|
|
|
|
|
|
SELECT * FROM #PerfDetail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
SELECT A.EmpId, A.Category ,SumType = CAST('Pay' AS VARCHAR(10)),PayTypeId,
|
|
|
|
|
SUM(A.PayAmt) AS PayAmt,SUM(DedCostPerf) AS DedCostPerf,SUM(A.Perf) AS Perf,SUM(A.Comm) AS Comm ,CAST(0 AS DECIMAL(18,6)) AS Quantity
|
|
|
|
|
INTO #Summary
|
|
|
|
|
FROM #PerfDetail AS A,#Employee AS E--,#Company AS C
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
-- AND A.CompId = C.FCompId
|
|
|
|
|
AND A.WorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
-- AND A.FIsExpired = 0
|
|
|
|
|
-- AND (@PayTypeNo = '' OR A.FPayTypeId IN(SELECT FPayTypeId FROM @PayTypeIds))
|
|
|
|
|
-- AND (@ItemNo = '' OR (A.FCategory = 'Item' AND A.FItemId IN(SELECT FItemId FROM @ItemIds) ))
|
|
|
|
|
GROUP BY A.EmpId, A.Category ,A.PayTypeId
|
|
|
|
|
|
|
|
|
|
INSERT #Summary(EmpId,Category,SumType,PayAmt,DedCostPerf,Perf,Comm)
|
|
|
|
|
SELECT EmpId,Category, 'Total',SUM(PayAmt),SUM(DedCostPerf),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Summary
|
|
|
|
|
GROUP BY EmpId,Category
|
|
|
|
|
|
|
|
|
|
INSERT #Summary(EmpId,Category,SumType,PayAmt,DedCostPerf,Perf,Comm)
|
|
|
|
|
SELECT EmpId,'All', 'Total',SUM(PayAmt),SUM(DedCostPerf),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Summary
|
|
|
|
|
WHERE SumType = 'Total'
|
|
|
|
|
GROUP BY EmpId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.Quantity = T2.Quantity
|
|
|
|
|
FROM #Summary AS A,
|
|
|
|
|
(
|
|
|
|
|
SELECT EmpId,Category,SUM(Quantity) AS Quantity
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT A.EmpId,Category,1 AS Quantity
|
|
|
|
|
FROM #PerfDetail AS A,#Employee AS E,#Company AS C
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
|
|
|
|
|
GROUP BY A.EmpId,A.Category,A.BillNo,A.BillDetailId,A.WorkType
|
|
|
|
|
) AS T GROUP BY T.EmpId,Category
|
|
|
|
|
) AS T2
|
|
|
|
|
WHERE T2.Category = A.Category
|
|
|
|
|
AND T2.EmpId = A.EmpId
|
|
|
|
|
AND A.SumType = 'Total'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT E.FEmpNo AS EmpNo,A.Category AS Category, A.SumType AS SumType, ISNULL(P.FName,'') AS PayTypeName,
|
|
|
|
|
ISNULL(A.PayAmt,0) AS PayAmt,ISNULL(A.Perf,0) AS Perf,ISNULL(A.DedCostPerf,0) AS DedCostPerf,ISNULL(A.Quantity,0) AS Quantity,ISNULL(A.Comm,0) AS Comm
|
|
|
|
|
FROM #Employee AS E,#Summary AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS P ON P.FId = A.PayTypeId
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
ORDER BY CASE WHEN ISNULL(P.FNo,'') = '' THEN '<EFBFBD><EFBFBD>' ELSE P.FNo END
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PGenerateEmpPerf','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PGenerateEmpPerf
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE dbo.PGenerateEmpPerf
|
|
|
|
|
(
|
|
|
|
|
@AllCompany BIT,
|
|
|
|
|
@FromDate CHAR(10),
|
|
|
|
|
@ToDate CHAR(10)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @Error INT
|
|
|
|
|
EXEC @Error = PGenerateEmpPerfDetail @AllCompany,@FromDate,@ToDate
|
|
|
|
|
IF @Error != 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
EXEC @Error = PGenerateEmpPerfFinish @AllCompany,@FromDate,@ToDate
|
|
|
|
|
IF @Error != 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
RETURN 0
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptWageReport02','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptWageReport02
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE PRptWageReport02
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
EXEC dbo.PDropTempTables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE @IParam VARCHAR(8000)
|
|
|
|
|
SET @IParam='FromDate="2014-01-17"ToDate="2015-01-17"FromEmpNo=""ToEmpNo=""FromItemTypeNo=""ToItemTypeNo=""CompNo="A001"IncChild="1"'
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
DECLARE @FromDate CHAR(10)
|
|
|
|
|
DECLARE @ToDate CHAR(10)
|
|
|
|
|
DECLARE @EmployeeText VARCHAR(1000)
|
|
|
|
|
DECLARE @ItemTypeNo VARCHAR(1000)
|
|
|
|
|
DECLARE @ItemKindNo VARCHAR(1000)
|
|
|
|
|
DECLARE @IncChild CHAR
|
|
|
|
|
DECLARE @CashierId BIGINT
|
|
|
|
|
DECLARE @DeptId BIGINT
|
|
|
|
|
DECLARE @ShowAmt INT
|
|
|
|
|
DECLARE @DeptNo VARCHAR(30)
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = dbo.FNGetParamCompId(@IParam)
|
|
|
|
|
SELECT @FromDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'FromDate'),23)
|
|
|
|
|
SELECT @ToDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'ToDate'),23)
|
|
|
|
|
SELECT @EmployeeText = ISNULL(dbo.FNGetParamValue(@IParam,'Employees'),'')
|
|
|
|
|
SELECT @ItemTypeNo = ISNULL(dbo.FNGetParamValue(@IParam,'ItemTypeNo'),'')
|
|
|
|
|
SELECT @ItemKindNo = ISNULL(dbo.FNGetParamValue(@IParam,'ItemKindNo'),'')
|
|
|
|
|
SELECT @ShowAmt = ISNULL(dbo.FNGetParamValue(@IParam,'ShowAmt'),0)
|
|
|
|
|
SELECT @DeptNo = ISNULL(dbo.FNGetParamValue(@IParam,'DeptNo'),'')
|
|
|
|
|
|
|
|
|
|
-- SELECT @ToItemTypeNo = dbo.FNGetParamValue(@IParam,'ToItemTypeNo')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@CompId,0) = 0
|
|
|
|
|
OR ISNULL(@ToDate,'') = ''
|
|
|
|
|
OR ISNULL(@FromDate,'') = ''
|
|
|
|
|
OR @FromDate > @ToDate
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF @DeptNo = '' OR @DeptNo = '*'
|
|
|
|
|
BEGIN
|
|
|
|
|
SET @DeptId = 0
|
|
|
|
|
END
|
|
|
|
|
SELECT @DeptId = FId FROM TBasicType WITH(NOLOCK) WHERE FKey = 'Department' AND FNo = @DeptNo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE @Employees TABLE
|
|
|
|
|
(
|
|
|
|
|
FNo VARCHAR(30)
|
|
|
|
|
)
|
|
|
|
|
INSERT @Employees
|
|
|
|
|
SELECT Field FROM dbo.FNStrSplit(@EmployeeText)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
SELECT A.FId AS FEmpId,FNo AS FEmpNo ,A.FName AS FEmpName
|
|
|
|
|
INTO #Employee
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK)
|
|
|
|
|
INNER JOIN TEmployeeSub AS B ON B.FEmpId = A.FId AND B.FCompId = @CompId
|
|
|
|
|
-- LEFT JOIN TEmployeeSub AS B WITH(NOLOCK) ON B.FEmpId=A.FId
|
|
|
|
|
WHERE A.FId != 0
|
|
|
|
|
AND B.FCompID = @CompId
|
|
|
|
|
AND (@DeptId = 0 OR A.FDeptId = @DeptId)
|
|
|
|
|
--AND (A.FCompId=@CompId OR B.FCompId=@CompId)
|
|
|
|
|
-- AND (@EmployeeText = '' OR B.FEmpNo IN (select FNo from @Employees )
|
|
|
|
|
-- OR A.FNo IN (select FNo from @Employees) )
|
|
|
|
|
AND (@EmployeeText = '' OR A.FNo IN (select FNo from @Employees) )
|
|
|
|
|
|
|
|
|
|
/* IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
*/
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT,
|
|
|
|
|
FCompNo VARCHAR(20)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
INSERT #Company (FCompID,FCompNo)
|
|
|
|
|
VALUES(@CompId,'')
|
|
|
|
|
|
|
|
|
|
DECLARE @Error INT
|
|
|
|
|
EXEC @Error = PGenerateEmpPerf 0,@FromDate,@ToDate
|
|
|
|
|
IF @Error != 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FId AS FTypeId, REPLACE(A.FNo,'.','.') AS FTypeNo, FName AS FTypeName,
|
|
|
|
|
A.FParentId AS FParentId, 'ItemType' AS FCategory
|
|
|
|
|
INTO #ItemType
|
|
|
|
|
FROM TBasicType AS A WITH(NOLOCK)
|
|
|
|
|
LEFT JOIN TBasicTypeSub AS B WITH(NOLOCK)
|
|
|
|
|
ON B.FBasicTypeId = A.FId
|
|
|
|
|
AND B.FCompId = @CompId
|
|
|
|
|
WHERE A.FKey = 'ItemType'
|
|
|
|
|
AND (@ItemTypeNo = '' OR A.FNo IN (SELECT Field FROM dbo.FNStrSplit(@ItemTypeNo)))
|
|
|
|
|
AND ((@CompId = 1 AND A.FEnabled = 1 ) OR ISNULL(B.FEnabled,1) = 1)
|
|
|
|
|
|
|
|
|
|
GROUP BY A.FId,A.FNo,A.FName,A.FParentId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FId AS FTypeId, REPLACE(A.FNo,'.','.') AS FTypeNo, FName AS FTypeName,
|
|
|
|
|
CAST(0 AS BIGINT) AS FParentId, 'ItemKind' AS FCategory
|
|
|
|
|
-- INTO #ItemKind
|
|
|
|
|
FROM TBasicType AS A WITH(NOLOCK)
|
|
|
|
|
WHERE A.FKey = 'ItemKind'
|
|
|
|
|
AND (@ItemKindNo = '' OR A.FNo IN (SELECT Field FROM dbo.FNStrSplit(@ItemKindNo)))
|
|
|
|
|
GROUP BY A.FId,A.FNo,A.FName
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Total
|
|
|
|
|
(
|
|
|
|
|
FEmpId BIGINT, --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
FType VARCHAR(20), --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FQty FLOAT, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FAmt FLOAT --ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #ItemDetail
|
|
|
|
|
(
|
|
|
|
|
FEmpId BIGINT, --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
FItemTypeId BIGINT, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Id
|
|
|
|
|
FCagegory VARCHAR(10) DEFAULT '', --<EFBFBD><EFBFBD><EFBFBD>༶<EFBFBD><EFBFBD> 'ItemType','ItemKind'
|
|
|
|
|
FTotalAmt FLOAT DEFAULT 0, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FTotalQty FLOAT DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCashAmt FLOAT DEFAULT 0, --<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCardAmt FLOAT DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FOtherAmt FLOAT DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashQty FLOAT DEFAULT 0, --<EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCardQty FLOAT DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FOtherQty FLOAT DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FDMQty1 FLOAT DEFAULT 0, --<EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD>ʽ1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FDMAmt1 FLOAT DEFAULT 0, --<EFBFBD><EFBFBD>ʽ1 ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FDMQty2 FLOAT DEFAULT 0, --
|
|
|
|
|
FDMAmt2 FLOAT DEFAULT 0,
|
|
|
|
|
FDMQty3 FLOAT DEFAULT 0,
|
|
|
|
|
FDMAmt3 FLOAT DEFAULT 0,
|
|
|
|
|
FDMQty4 FLOAT DEFAULT 0,
|
|
|
|
|
FDMAmt4 FLOAT DEFAULT 0,
|
|
|
|
|
FWorkQty1 FLOAT DEFAULT 0, --<EFBFBD><EFBFBD>λ1
|
|
|
|
|
FWorkAmt1 FLOAT DEFAULT 0, --<EFBFBD><EFBFBD>λ1 ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkQty2 FLOAT DEFAULT 0, --
|
|
|
|
|
FWorkAmt2 FLOAT DEFAULT 0,
|
|
|
|
|
FWorkQty3 FLOAT DEFAULT 0,
|
|
|
|
|
FWorkAmt3 FLOAT DEFAULT 0,
|
|
|
|
|
FWorkQty4 FLOAT DEFAULT 0,
|
|
|
|
|
FWorkAmt4 FLOAT DEFAULT 0,
|
|
|
|
|
)
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> #EmpPerfDetail
|
|
|
|
|
SELECT A.*,CAST('' AS VARCHAR(20)) AS FPayTypeCatg /*֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ֽ<EFBFBD>,<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)*/
|
|
|
|
|
INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A, #Employee AS E,#Company AS C
|
|
|
|
|
WHERE A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
AND C.FCompId = A.FCompId
|
|
|
|
|
AND A.FEmpId = E.FEmpId
|
|
|
|
|
AND A.FIsExpired = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬<EFBFBD>㷨ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾΪ
|
|
|
|
|
IF @ShowAmt = 1
|
|
|
|
|
BEGIN
|
|
|
|
|
UPDATE #EmpPerfDetail SET FPerf = FAmt
|
|
|
|
|
END
|
|
|
|
|
ELSE IF @ShowAmt = 2
|
|
|
|
|
BEGIN
|
|
|
|
|
UPDATE #EmpPerfDetail SET FPerf = FDedCostPerf
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FPayTypeCatg = CASE WHEN A.FPayTypeId IN(1,2) THEN 'Cash' --<EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
WHEN (A.FPayTypeId IN(6) OR ISNULL(S.FIsAccount,0) = 1) THEN 'Card' --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ELSE 'Other' END --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FROM #EmpPerfDetail AS A,TPayAccount AS S WITH(NOLOCK)
|
|
|
|
|
WHERE A.FPayTypeId = S.FId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -- DEBUG --<EFBFBD>д<EFBFBD><EFBFBD>Ľ<EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FItemTypeId = B.FTypeId
|
|
|
|
|
FROM #EmpPerfDetail AS A, TItem AS B WITH(NOLOCK)
|
|
|
|
|
WHERE A.FItemId = B.FId
|
|
|
|
|
AND A.FCategory = 'Item'
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ÿ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FEmpId AS FEmpId,
|
|
|
|
|
A.FBillId AS FBillId,
|
|
|
|
|
MAX(FCustQuantity) AS FCustQuantity, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(A.FCustGender)) = 1 THEN 'ItemMale' ELSE 'ItemFemale' END AS FCustGender, --<EFBFBD>ͻ<EFBFBD><EFBFBD>Ա<EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(A.FCustNewOld)) = 0 THEN 'ItemNew' ELSE 'ItemOld' END AS FCustNewOld, --<EFBFBD>¿<EFBFBD><EFBFBD>Ͽ<EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(CASE WHEN A.FDispatchMode = 10001 THEN 1 ELSE 2 END)) = 1
|
|
|
|
|
THEN 'ItemDMode1' ELSE 'ItemDMode2' END AS FDispatchMode, --1ָ<EFBFBD><EFBFBD>,2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
'Item' + MIN(A.FPayTypeCatg) AS FPayCatg --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INTO #ItemBill
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S WITH(NOLOCK) ON S.FId = A.FPayTypeId
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FEmpId,A.FBillId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
|
|
|
|
|
SELECT A.FEmpId,A.FCagegory, SUM(A.FQty) AS FQty, SUM(A.FAmt) AS FAmt
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId,'ItemTotal' AS FCagegory, SUM(FCustQuantity) AS FQty, 0 AS FAmt FROM #ItemBill GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId,'ItemTotal' AS FCagegory, CAST(0 AS DECIMAL(18,6)) AS FQty, SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD>Ͳ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId,FDispatchMode AS FCagegory,SUM(FCustQuantity) AS FQty,
|
|
|
|
|
0 AS FAmt
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId, FDispatchMode
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
--ÿ<EFBFBD>ַ<EFBFBD>ʽ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>,
|
|
|
|
|
SELECT FEmpId,
|
|
|
|
|
CASE FDispatchMode WHEN 10001 THEN 'ItemDMode1'
|
|
|
|
|
WHEN 10002 THEN 'ItemDMode2'
|
|
|
|
|
WHEN 10003 THEN 'ItemDMode3'
|
|
|
|
|
WHEN 10004 THEN 'ItemDMode4'
|
|
|
|
|
ELSE '' END,
|
|
|
|
|
0 AS FQty,SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FDispatchMode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>λҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT FEmpId,
|
|
|
|
|
CASE FWorkType WHEN 11001 THEN 'ItemWork1'
|
|
|
|
|
WHEN 11002 THEN 'ItemWork2'
|
|
|
|
|
WHEN 11003 THEN 'ItemWork3'
|
|
|
|
|
WHEN 11004 THEN 'ItemWork4'
|
|
|
|
|
ELSE '' END,
|
|
|
|
|
SUM(FSplitQuantity) AS FQty,SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FWorkType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD>Ů<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FCustGender AS FType, SUM(FCustQuantity) AS FQty, 0 AS FAmt
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId, FCustGender
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD>п<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, CASE FCustGender WHEN 1 THEN 'ItemMale' ELSE 'ItemFemale' END AS FType,
|
|
|
|
|
0 AS FQty, SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FCustGender
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FCustNewOld AS FType, SUM(FCustQuantity) AS FQty, 0 AS FAmt
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId, FCustNewOld
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, CASE FCustNewOld WHEN 0 THEN 'ItemNew' ELSE 'ItemOld' END AS FType,
|
|
|
|
|
0 AS FQty, SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FCustNewOld
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>¿<EFBFBD><EFBFBD>Ͽ<EFBFBD>,<EFBFBD><EFBFBD>ʱû<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FPayCatg AS FType,
|
|
|
|
|
SUM(FCustQuantity) AS FQty,
|
|
|
|
|
0 AS FAmt
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId, FPayCatg
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD>ֽ<EFBFBD>,<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FEmpId,
|
|
|
|
|
'Item' + A.FPayTypeCatg,
|
|
|
|
|
0 AS FQty,
|
|
|
|
|
SUM(A.FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
WHERE A.FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FEmpId,A.FPayTypeCatg
|
|
|
|
|
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FCagegory
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT A.FEmpId , A.FType, SUM(A.FQty) AS FQty , SUM(A.FAmt) AS FAmt
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--<EFBFBD><EFBFBD>Ʒ<EFBFBD>ܼ<EFBFBD>
|
|
|
|
|
SELECT A.FEmpId, 'GoodsTotal' AS FType, SUM(A.FQuantity) AS FQty, SUM(A.FPerf) AS FAmt
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD>ȡһ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT B.FEmpId, B.FBillDetailId, B.FQuantity, SUM(B.FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail AS B
|
|
|
|
|
WHERE B.FCategory = 'Goods'
|
|
|
|
|
GROUP BY B.FEmpId, B.FBillDetailId, B.FQuantity
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
SELECT A.FEmpId,
|
|
|
|
|
'Goods' + A.FPayTypeCatg AS FType,
|
|
|
|
|
SUM(A.FQuantity) AS FQty,
|
|
|
|
|
SUM(A.FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
WHERE A.FCategory = 'Goods'
|
|
|
|
|
GROUP BY A.FEmpId,A.FPayTypeCatg
|
|
|
|
|
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FType
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD>ֵ
|
|
|
|
|
SELECT FEmpId, FCategory, COUNT(1) AS FQty, SUM(Amt) AS FAmt
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT FEmpId, FCategory, 1 AS FQty, SUM(FPerf) AS Amt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN ('CardSale','CardRchg')
|
|
|
|
|
GROUP BY FEmpId,FCategory,FBillId
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY FEmpId, FCategory
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId, 'CardTotal', SUM(FQty) AS FQty, SUM(FAmt) AS FAmt
|
|
|
|
|
FROM #Total
|
|
|
|
|
WHERE FType IN('CardSale','CardRchg')
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>Ƴ̺<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,FCategory, SUM(FQty) AS FQty, SUM(FAmt) AS FAmt
|
|
|
|
|
FROM(
|
|
|
|
|
SELECT FEmpId, 'CourseSale' AS FCategory, FQuantity AS FQty, SUM(FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN( 'CourseSale','CoursePackSale')
|
|
|
|
|
GROUP BY FEmpId,FBillId,FBillDetailId,FQuantity,FCategory
|
|
|
|
|
) as A
|
|
|
|
|
GROUP BY FEmpId,FCategory
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
INSERT #ItemDetail(FEmpId,FCagegory,FItemTypeId, FTotalAmt, FTotalQty,
|
|
|
|
|
FCashAmt, FCardAmt, FOtherAmt, FCashQty, FCardQty, FOtherQty,
|
|
|
|
|
FDMQty1, FDMAmt1, FDMQty2, FDMAmt2, FDMQty3,FDMAmt3,FDMQty4,FDMAmt4,
|
|
|
|
|
FWorkQty1, FWorkAmt1, FWorkQty2, FWorkAmt2, FWorkQty3,FWorkAmt3,FWorkQty4,FWorkAmt4)
|
|
|
|
|
SELECT A.FEmpId, A.FCagegory, A.FItemTypeId,SUM(FTotalAmt), SUM(FTotalQty),
|
|
|
|
|
SUM(FCashAmt), SUM(FCardAmt), SUM(FOtherAmt), SUM(FCashQty), SUM(FCardQty), SUM(FOtherQty),
|
|
|
|
|
SUM(FDMQty1), SUM(FDMAmt1), SUM(FDMQty2), SUM(FDMAmt2), SUM(FDMQty3),SUM(FDMAmt3),SUM(FDMQty4),SUM(FDMAmt4),
|
|
|
|
|
SUM(FWorkQty1), SUM(FWorkAmt1), SUM(FWorkQty2), SUM(FWorkAmt2), SUM(FWorkQty3),SUM(FWorkAmt3),SUM(FWorkQty4),SUM(FWorkAmt4)
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD>
|
|
|
|
|
SELECT A.FEmpId ,'ItemType' AS FCagegory,A.FItemTypeId, SUM(A.FQuantity) AS FTotalQty, SUM(FPerf) AS FTotalAmt,
|
|
|
|
|
0 AS FCashQty, 0 AS FCashAmt, 0 AS FCardQty, 0 AS FCardAmt, 0 AS FOtherQty, 0 AS FOtherAmt,
|
|
|
|
|
0 AS FDMQty1, 0 AS FDMAmt1,0 AS FDMQty2, 0 AS FDMAmt2,0 AS FDMQty3, 0 AS FDMAmt3,0 AS FDMQty4, 0 AS FDMAmt4,
|
|
|
|
|
0 AS FWorkQty1, 0 AS FWorkAmt1,0 AS FWorkQty2, 0 AS FWorkAmt2,0 AS FWorkQty3, 0 AS FWorkAmt3,0 AS FWorkQty4, 0 AS FWorkAmt4
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT FEmpId,FItemTypeId,FQuantity,SUM(FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId,FItemTypeId,FBillDetailId, FQuantity
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY FEmpId,FItemTypeId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
|
|
--ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>ͳ<EFBFBD><EFBFBD> ,<EFBFBD>ֽ<EFBFBD>,<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
|
|
|
|
SELECT FEmpId, 'ItemType' AS FCagegory, FItemTypeId, 0 AS FTotalQty, 0 AS FTotalAmt,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Cash' THEN FQuantity ELSE 0 END) AS FCashQty,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Cash' THEN FPerf ELSE 0 END) AS FCashAmt,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Card' THEN FQuantity ELSE 0 END) AS FCardQty,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Card' THEN FPerf ELSE 0 END) AS FCardAmt,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Other' THEN FQuantity ELSE 0 END) AS FOtherQty,
|
|
|
|
|
SUM(CASE WHEN FPayTypeCatg = 'Other' THEN FPerf ELSE 0 END) AS FOtherAmt,
|
|
|
|
|
0 AS FDMQty1, 0 AS FDMAmt1,0 AS FDMQty2, 0 AS FDMAmt2,0 AS FDMQty3, 0 AS FDMAmt3,0 AS FDMQty4, 0 AS FDMAmt4,
|
|
|
|
|
0 AS FWorkQty1, 0 AS FWorkAmt1,0 AS FWorkQty2, 0 AS FWorkAmt2,0 AS FWorkQty3, 0 AS FWorkAmt3,0 AS FWorkQty4, 0 AS FWorkAmt4
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀͬһ<EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FBillDetailId, FItemTypeId, FQuantity,FPayTypeCatg, SUM(FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FBillDetailId, FItemTypeId, FQuantity,FPayTypeCatg
|
|
|
|
|
|
|
|
|
|
--SELECT * FROM #EmpPerfDetail WHERE FCategory = 'Item' AND FBillDetailId = 5036650046547848466
|
|
|
|
|
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FItemTypeId
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>𰴷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽͳ<EFBFBD><EFBFBD>, <EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>,...
|
|
|
|
|
SELECT FEmpId,'ItemType' AS FCagegory, FItemTypeId, 0 AS FTotalQty, 0 AS FTotalAmt,
|
|
|
|
|
0 AS FCashQty, 0 AS FCashAmt, 0 AS FCardQty, 0 AS FCardAmt, 0 AS FOtherQty, 0 AS FOtherAmt,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10001 THEN FQuantity ELSE 0 END) AS FDMQty1,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10001 THEN FPerf ELSE 0 END) AS FDMAmt1,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10002 THEN FQuantity ELSE 0 END) AS FDMQty2,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10002 THEN FPerf ELSE 0 END) AS FDMAmt2,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10003 THEN FQuantity ELSE 0 END) AS FDMQty3,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10003 THEN FPerf ELSE 0 END) AS FDMAmt3,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10004 THEN FQuantity ELSE 0 END) AS FDMQty4,
|
|
|
|
|
SUM(CASE WHEN FDispatchMode = 10004 THEN FPerf ELSE 0 END) AS FDMAmt4,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11001 THEN FQuantity ELSE 0 END) AS FWorkQty1,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11001 THEN FPerf ELSE 0 END) AS FWorkAmt1,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11002 THEN FQuantity ELSE 0 END) AS FWorkQty2,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11002 THEN FPerf ELSE 0 END) AS FWorkAmt2,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11003 THEN FQuantity ELSE 0 END) AS FWorkQty3,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11003 THEN FPerf ELSE 0 END) AS FWorkAmt3,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11004 THEN FQuantity ELSE 0 END) AS FWorkQty4,
|
|
|
|
|
SUM(CASE WHEN FWorkType = 11004 THEN FPerf ELSE 0 END) AS FWorkAmt4
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FBillDetailId, FItemTypeId, FQuantity,FDispatchMode,FWorkType, SUM(FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId, FBillDetailId, FItemTypeId, FQuantity,FDispatchMode,FWorkType
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FItemTypeId
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FItemTypeId,A.FCagegory
|
|
|
|
|
|
|
|
|
|
--ͳ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|
|
|
|
INSERT #ItemDetail(FEmpId,FCagegory,FItemTypeId, FTotalAmt, FTotalQty,
|
|
|
|
|
FCashAmt, FCardAmt, FOtherAmt, FCashQty, FCardQty, FOtherQty,
|
|
|
|
|
FDMQty1, FDMAmt1, FDMQty2, FDMAmt2, FDMQty3,FDMAmt3,FDMQty4,FDMAmt4,
|
|
|
|
|
FWorkQty1, FWorkAmt1, FWorkQty2, FWorkAmt2, FWorkQty3,FWorkAmt3,FWorkQty4,FWorkAmt4)
|
|
|
|
|
SELECT A.FEmpId, 'ItemKind', B.FParentId, SUM(FTotalAmt), SUM(FTotalQty),
|
|
|
|
|
SUM(FCashAmt), SUM(FCardAmt), SUM(FOtherAmt), SUM(FCashQty), SUM(FCardQty), SUM(FOtherQty),
|
|
|
|
|
SUM(FDMQty1), SUM(FDMAmt1), SUM(FDMQty2), SUM(FDMAmt2), SUM(FDMQty3),SUM(FDMAmt3),SUM(FDMQty4),SUM(FDMAmt4),
|
|
|
|
|
SUM(FWorkQty1), SUM(FWorkAmt1), SUM(FWorkQty2), SUM(FWorkAmt2), SUM(FWorkQty3),SUM(FWorkAmt3),SUM(FWorkQty4),SUM(FWorkAmt4)
|
|
|
|
|
FROM #ItemDetail AS A,#ItemType AS B
|
|
|
|
|
WHERE A.FItemTypeId = B.FTypeId
|
|
|
|
|
GROUP BY A.FEmpId,B.FParentId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CommTotal',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'ItemComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'GoodsComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Goods'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CardComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN ('CardSale','CardRchg')
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CourseComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN ('CourseSale','CoursePackSale')
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>
|
|
|
|
|
--Total <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT 0 AS FEmpId,FType, SUM(FQty) AS FQty, SUM(FAmt) AS FAmt
|
|
|
|
|
FROM #Total
|
|
|
|
|
GROUP BY FType
|
|
|
|
|
|
|
|
|
|
--ItemDetail <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>
|
|
|
|
|
INSERT #ItemDetail(FEmpId,FItemTypeId, FTotalAmt, FTotalQty,
|
|
|
|
|
FCashAmt, FCardAmt, FOtherAmt, FCashQty, FCardQty, FOtherQty,
|
|
|
|
|
FDMQty1, FDMAmt1, FDMQty2, FDMAmt2, FDMQty3,FDMAmt3,FDMQty4,FDMAmt4,
|
|
|
|
|
FWorkQty1, FWorkAmt1, FWorkQty2, FWorkAmt2, FWorkQty3,FWorkAmt3,FWorkQty4,FWorkAmt4)
|
|
|
|
|
SELECT 0, A.FItemTypeId, SUM(FTotalAmt), SUM(FTotalQty),
|
|
|
|
|
SUM(FCashAmt), SUM(FCardAmt), SUM(FOtherAmt), SUM(FCashQty), SUM(FCardQty), SUM(FOtherQty),
|
|
|
|
|
SUM(FDMQty1), SUM(FDMAmt1), SUM(FDMQty2), SUM(FDMAmt2), SUM(FDMQty3),SUM(FDMAmt3),SUM(FDMQty4),SUM(FDMAmt4),
|
|
|
|
|
SUM(FWorkQty1), SUM(FWorkAmt1), SUM(FWorkQty2), SUM(FWorkAmt2), SUM(FWorkQty3),SUM(FWorkAmt3),SUM(FWorkQty4),SUM(FWorkAmt4)
|
|
|
|
|
FROM #ItemDetail AS A
|
|
|
|
|
GROUP BY FItemTypeId
|
|
|
|
|
|
|
|
|
|
SELECT FEmpId AS EmpId,FEmpNo AS EmpNo,FEmpName AS EmpName
|
|
|
|
|
FROM #Employee AS B
|
|
|
|
|
WHERE EXISTS(SELECT 1 FROM #EmpPerfDetail AS A WHERE A.FEmpId = B.FEmpId)
|
|
|
|
|
ORDER BY FEmpNo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>ѱ<EFBFBD><EFBFBD>ż<EFBFBD>ǰ
|
|
|
|
|
|
|
|
|
|
SELECT FCategory + FTypeNo AS TypeNo, FTypeName AS TypeName ,FCategory AS Category
|
|
|
|
|
FROM #ItemType
|
|
|
|
|
ORDER BY FCategory,FTypeNo
|
|
|
|
|
|
|
|
|
|
SELECT A.FEmpId AS EmpId, FType AS Type, FQty AS Qty , FAmt AS Amt
|
|
|
|
|
FROM #Total AS A ,#Employee AS E
|
|
|
|
|
WHERE A.FEmpId = E.FEmpId
|
|
|
|
|
ORDER BY E.FEmpNo
|
|
|
|
|
|
|
|
|
|
SELECT A.FEmpId AS EmpId, --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
A.FCagegory + B.FTypeNo AS ItemTypeNo, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ż<EFBFBD>ǰ
|
|
|
|
|
A.FCagegory AS Category,
|
|
|
|
|
FTotalAmt AS TotalAmt, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FTotalQty AS TotalQty, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCashAmt AS CashAmt, --<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCardAmt AS CardAmt, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FOtherAmt AS OtherAmt, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashQty AS CashQty, --<EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCardQty AS CardQty, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FOtherQty AS OtherQty, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FDMQty1 AS DMQty1, --<EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD>ʽ1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FDMAmt1 AS DMAmt1, --<EFBFBD><EFBFBD>ʽ1 ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FDMQty2 AS DMQty2, --
|
|
|
|
|
FDMAmt2 AS DMAmt2,
|
|
|
|
|
FDMQty3 AS DMQty3,
|
|
|
|
|
FDMAmt3 AS DMAmt3,
|
|
|
|
|
FDMQty4 AS DMQty4,
|
|
|
|
|
FDMAmt4 AS DMAmt4,
|
|
|
|
|
FWorkQty1 AS WorkQty1, --<EFBFBD><EFBFBD>λ1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FWorkAmt1 AS WorkAmt1, --<EFBFBD><EFBFBD>λ1ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkQty2 AS WorkQty2, --
|
|
|
|
|
FWorkAmt2 AS WorkAmt2,
|
|
|
|
|
FWorkQty3 AS WorkQty3,
|
|
|
|
|
FWorkAmt3 AS WorkAmt3,
|
|
|
|
|
FWorkQty4 AS WorkQty4,
|
|
|
|
|
FWorkAmt4 AS WorkAmt4
|
|
|
|
|
FROM #ItemDetail AS A, #ItemType AS B ,#Employee AS E
|
|
|
|
|
WHERE B.FTypeId = A.FItemTypeId
|
|
|
|
|
AND A.FEmpId = E.FEmpId
|
|
|
|
|
ORDER BY E.FEmpNo,B.FTypeNo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptWageReport03','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptWageReport03
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE PRptWageReport03
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
EXEC dbo.PDropTempTables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE @IParam VARCHAR(8000)
|
|
|
|
|
SET @IParam='FromDate="2014-01-17"ToDate="2015-01-17"FromEmpNo=""ToEmpNo=""FromItemTypeNo=""ToItemTypeNo=""CompNo="A001"IncChild="1"'
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
DECLARE @FromDate CHAR(10)
|
|
|
|
|
DECLARE @ToDate CHAR(10)
|
|
|
|
|
DECLARE @EmployeeText VARCHAR(30)
|
|
|
|
|
DECLARE @IncChild CHAR
|
|
|
|
|
DECLARE @CashierId BIGINT
|
|
|
|
|
DECLARE @DeptId BIGINT
|
|
|
|
|
DECLARE @ShowAmt INT --ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾΪӪҵ<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @DeptNo VARCHAR(30)
|
|
|
|
|
DECLARE @LoadDetail BIT --<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ϸ
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = dbo.FNGetParamCompId(@IParam)
|
|
|
|
|
SELECT @FromDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'FromDate'),23)
|
|
|
|
|
SELECT @ToDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'ToDate'),23)
|
|
|
|
|
SELECT @EmployeeText = ISNULL(dbo.FNGetParamValue(@IParam,'Employees'),'')
|
|
|
|
|
SELECT @ShowAmt = ISNULL(dbo.FNGetParamValue(@IParam,'ShowAmt'),0)
|
|
|
|
|
SELECT @DeptNo = ISNULL(dbo.FNGetParamValue(@IParam,'DeptNo'),'')
|
|
|
|
|
SELECT @LoadDetail = ISNULL(dbo.FNGetParamValue(@IParam,'LoadDetail'),0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@CompId,0) = 0
|
|
|
|
|
OR ISNULL(@ToDate,'') = ''
|
|
|
|
|
OR ISNULL(@FromDate,'') = ''
|
|
|
|
|
OR @FromDate > @ToDate
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF @DeptNo = '' OR @DeptNo = '*'
|
|
|
|
|
BEGIN
|
|
|
|
|
SET @DeptId = 0
|
|
|
|
|
END
|
|
|
|
|
SELECT @DeptId = FId FROM TBasicType WITH(NOLOCK) WHERE FKey = 'Department' AND FNo = @DeptNo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DECLARE @Employees TABLE
|
|
|
|
|
(
|
|
|
|
|
FNo VARCHAR(30)
|
|
|
|
|
)
|
|
|
|
|
CREATE TABLE #PerfTotal
|
|
|
|
|
(
|
|
|
|
|
FEmpId BIGINT NOT NULL, --Ա<EFBFBD><EFBFBD>ID
|
|
|
|
|
FEmpNo VARCHAR(30) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FEmpName VARCHAR(50) NOT NULL, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCustQty FLOAT NOT NULL DEFAULT 0, --<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FPerfTotal FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM1Qty FLOAT NOT NULL DEFAULT 0, --ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM2Qty FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM3Qty FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ʽ3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM4Qty FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ʽ4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM1Perf FLOAT NOT NULL DEFAULT 0, --ָ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM2Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM3Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ʽ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM4Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ʽ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType1Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>λ1ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType2Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>λ2ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType3Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>λ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType4Perf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>λ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfTotal FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfCashPay FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>Ŀ<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfCardPay FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfOtherPay FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FGoodsPerf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>Ʒҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCourseSalePerf FLOAT NOT NULL DEFAULT 0, --<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCardSalePerf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FMemSalePerf FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FLaborPerf FLOAT NOT NULL DEFAULT 0, --<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashPerfTotal FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashAmtTotal FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FDM1Rate FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
|
|
|
|
FSanction FLOAT NOT NULL DEFAULT 0, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCommTotal FLOAT NOT NULL DEFAULT 0 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT @Employees
|
|
|
|
|
SELECT Field FROM dbo.FNStrSplit(@EmployeeText)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
|
|
|
|
|
INSERT #PerfTotal(FEmpId,FEmpNo,FEmpName)
|
|
|
|
|
SELECT A.FId AS FEmpId,FNo AS FEmpNo ,A.FName AS FEmpName
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK) ,TEmployeeSub AS B WITH(NOLOCK)
|
|
|
|
|
WHERE A.FId != 0
|
|
|
|
|
AND B.FCompId = @CompId
|
|
|
|
|
AND B.FEmpId = A.FId
|
|
|
|
|
AND (@DeptId = 0 OR A.FDeptId = @DeptId)
|
|
|
|
|
AND (@EmployeeText = '' OR A.FNo IN (select FNo from @Employees) )
|
|
|
|
|
|
|
|
|
|
/* IF @@ROWCOUNT = 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT,
|
|
|
|
|
FCompNo VARCHAR(20)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT #Company (FCompID,FCompNo)
|
|
|
|
|
VALUES(@CompId,'')
|
|
|
|
|
|
|
|
|
|
DECLARE @Error INT
|
|
|
|
|
EXEC @Error = PGenerateEmpPerf 0,@FromDate,@ToDate
|
|
|
|
|
IF @Error != 0
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN -1
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
SELECT FParentId,FChildId,FLevel
|
|
|
|
|
INTO #Tree
|
|
|
|
|
FROM TBasicTypeTree
|
|
|
|
|
WHERE FKey = 'ItemType'
|
|
|
|
|
ORDER BY FLevel DESC --<EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> #EmpPerfDetail
|
|
|
|
|
SELECT A.*,CAST('' AS VARCHAR(20)) AS FPayTypeCatg /*֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD>ֽ<EFBFBD>,<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)*/
|
|
|
|
|
INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A, #PerfTotal AS E,#Company AS C
|
|
|
|
|
WHERE A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
AND C.FCompId = A.FCompId
|
|
|
|
|
AND A.FEmpId = E.FEmpId
|
|
|
|
|
AND A.FIsExpired = 0
|
|
|
|
|
|
|
|
|
|
SELECT FEmpId
|
|
|
|
|
INTO #Employee
|
|
|
|
|
FROM #PerfTotal
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬<EFBFBD>㷨ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ʾΪӪҵ<EFBFBD><EFBFBD>
|
|
|
|
|
IF @ShowAmt = 1
|
|
|
|
|
BEGIN
|
|
|
|
|
UPDATE #EmpPerfDetail SET FPerf = FAmt
|
|
|
|
|
END
|
|
|
|
|
ELSE IF @ShowAmt = 2
|
|
|
|
|
BEGIN
|
|
|
|
|
UPDATE #EmpPerfDetail SET FPerf = FDedCostPerf
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FPayTypeCatg = CASE WHEN A.FPayTypeId IN(1,2) THEN 'Cash' --<EFBFBD>ֽ<EFBFBD>
|
|
|
|
|
WHEN (A.FPayTypeId IN(6) OR ISNULL(S.FIsAccount,0) = 1) THEN 'Card' --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
ELSE 'Other' END --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FROM #EmpPerfDetail AS A,TPayAccount AS S WITH(NOLOCK)
|
|
|
|
|
WHERE A.FPayTypeId = S.FId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -- DEBUG --<EFBFBD>д<EFBFBD><EFBFBD>Ľ<EFBFBD>
|
|
|
|
|
/* UPDATE A
|
|
|
|
|
SET A.FItemTypeId = B.FTypeId
|
|
|
|
|
FROM #EmpPerfDetail AS A, TItem AS B WITH(NOLOCK)
|
|
|
|
|
WHERE A.FItemId = B.FId
|
|
|
|
|
AND A.FCategory = 'Item'*/
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ÿ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FEmpId AS FEmpId,
|
|
|
|
|
A.FBillId AS FBillId,
|
|
|
|
|
MAX(A.FCustQuantity) AS FCustQuantity,
|
|
|
|
|
CASE WHEN (MIN(A.FCustGender)) = 1 THEN 'ItemMale' ELSE 'ItemFemale' END AS FCustGender, --<EFBFBD>ͻ<EFBFBD><EFBFBD>Ա<EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(CASE WHEN A.FDispatchMode = 10001 THEN 1 ELSE 2 END)) = 1
|
|
|
|
|
THEN 'ItemDMode1' ELSE 'ItemDMode2' END AS FDispatchMode, --1ָ<EFBFBD><EFBFBD>,2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
'Item' + MIN(A.FPayTypeCatg) AS FPayCatg --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INTO #ItemBill
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S WITH(NOLOCK) ON S.FId = A.FPayTypeId
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FEmpId,A.FBillId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FCustQty = B.FQty
|
|
|
|
|
FROM #PerfTotal AS A, (SELECT FEmpId, SUM(FCustQuantity) AS FQty
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE B.FEmpId = A.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FItemPerfTotal = B.FPerf
|
|
|
|
|
FROM #PerfTotal AS A, (SELECT FEmpId,SUM(CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ) AS FPerf FROM #EmpPerfDetail WHERE FCategory = 'Item' GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE B.FEmpId = A.FEmpId
|
|
|
|
|
|
|
|
|
|
--ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FItemDM1Qty = B.FDM1Qty,
|
|
|
|
|
A.FItemDM2Qty = B.FDM2Qty,
|
|
|
|
|
A.FItemDM3Qty = 0,
|
|
|
|
|
A.FItemDM4Qty = 0
|
|
|
|
|
FROM #PerfTotal AS A,
|
|
|
|
|
( SELECT FEmpId,SUM(CASE FDispatchMode WHEN 'ItemDMode1' THEN FCustQuantity ELSE 0 END) AS FDM1Qty,
|
|
|
|
|
SUM(CASE FDispatchMode WHEN 'ItemDMode2' THEN FCustQuantity ELSE 0 END) AS FDM2Qty
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId ) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--ָ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FItemDM1Perf = B.FDM1Perf,
|
|
|
|
|
A.FItemDM2Perf = B.FDM2Perf,
|
|
|
|
|
A.FItemDM3Perf = B.FDM3Perf,
|
|
|
|
|
A.FItemDM4Perf = B.FDM4Perf
|
|
|
|
|
FROM #PerfTotal AS A,
|
|
|
|
|
( SELECT FEmpId,SUM(CASE FDispatchMode WHEN 10001 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FDM1Perf,
|
|
|
|
|
SUM(CASE FDispatchMode WHEN 10002 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FDM2Perf,
|
|
|
|
|
SUM(CASE FDispatchMode WHEN 10003 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FDM3Perf,
|
|
|
|
|
SUM(CASE FDispatchMode WHEN 10004 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FDM4Perf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
GROUP BY FEmpId ) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FWorkType1Perf = B.FWorkType1Perf,
|
|
|
|
|
A.FWorkType2Perf = B.FWorkType2Perf,
|
|
|
|
|
A.FWorkType3Perf = B.FWorkType3Perf,
|
|
|
|
|
A.FWorkType4Perf = B.FWorkType4Perf
|
|
|
|
|
FROM #PerfTotal AS A,
|
|
|
|
|
( SELECT FEmpId,SUM(CASE FWorkType WHEN 11001 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FWorkType1Perf,
|
|
|
|
|
SUM(CASE FWorkType WHEN 11002 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FWorkType2Perf,
|
|
|
|
|
SUM(CASE FWorkType WHEN 11003 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FWorkType3Perf,
|
|
|
|
|
SUM(CASE FWorkType WHEN 11004 THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FWorkType4Perf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
GROUP BY FEmpId ) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>Ŀ<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FItemPerfCashPay = B.FCash,
|
|
|
|
|
A.FItemPerfCardPay = B.FCard,
|
|
|
|
|
A.FItemPerfOtherPay = B.FOther
|
|
|
|
|
FROM #PerfTotal AS A,
|
|
|
|
|
(SELECT FEmpId,SUM(CASE FPayTypeCatg WHEN 'Cash' THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FCash,
|
|
|
|
|
SUM(CASE FPayTypeCatg WHEN 'Card' THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FCard,
|
|
|
|
|
SUM(CASE FPayTypeCatg WHEN 'Other' THEN CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ELSE 0 END) AS FOther
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>¿<EFBFBD><EFBFBD>Ͽ<EFBFBD>,<EFBFBD><EFBFBD>ʱû<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT FEmpId, FPayCatg AS FType,
|
|
|
|
|
COUNT(1) AS FQty,
|
|
|
|
|
0 AS FAmt
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
GROUP BY FEmpId, FPayCatg
|
|
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
--<EFBFBD>ֽ<EFBFBD>,<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FEmpId,
|
|
|
|
|
'Item' + A.FPayTypeCatg,
|
|
|
|
|
0 AS FQty,
|
|
|
|
|
SUM(A.FPerf) AS FAmt
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
WHERE A.FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FEmpId,A.FPayTypeCatg
|
|
|
|
|
|
|
|
|
|
) AS A
|
|
|
|
|
GROUP BY A.FEmpId,A.FType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CommTotal',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'ItemComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'GoodsComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'Goods'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CardComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN ('CardSale','CardRchg')
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT FEmpId,'CourseComm',0 AS FQty, SUM(FComm)
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory = 'SellCourse'
|
|
|
|
|
GROUP BY FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>
|
|
|
|
|
--Total <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>
|
|
|
|
|
INSERT #Total(FEmpId,FType,FQty,FAmt)
|
|
|
|
|
SELECT 0 AS FEmpId,FType, SUM(FQty) AS FQty, SUM(FAmt) AS FAmt
|
|
|
|
|
FROM #Total
|
|
|
|
|
GROUP BY FType
|
|
|
|
|
|
|
|
|
|
SELECT FEmpId AS EmpId,FEmpNo AS EmpNo,FEmpName AS EmpName
|
|
|
|
|
FROM #Employee
|
|
|
|
|
ORDER BY FEmpNo
|
|
|
|
|
|
|
|
|
|
SELECT A.FEmpId AS EmpId, FType AS Type, FQty AS Qty , FAmt AS Amt
|
|
|
|
|
FROM #Total AS A ,#Employee AS E
|
|
|
|
|
WHERE A.FEmpId = E.FEmpId
|
|
|
|
|
ORDER BY E.FEmpNo
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FGoodsPerf = B.FPerf
|
|
|
|
|
FROM #PerfTotal AS A, (SELECT FEmpId, SUM(CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ) AS FPerf FROM #EmpPerfDetail WHERE FCategory = 'Goods' GROUP BY FEmpId ) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FCardSalePerf = B.FPerf
|
|
|
|
|
FROM #PerfTotal AS A,(SELECT FEmpId,SUM(FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN('CardSale','CardRchg','','')
|
|
|
|
|
GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FCourseSalePerf = B.FPerf
|
|
|
|
|
FROM #PerfTotal AS A,(SELECT FEmpId,SUM(FPerf) AS FPerf
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
WHERE FCategory IN('','','CourseSale','CoursePackSale')
|
|
|
|
|
GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FMemSalePerf = A.FCardSalePerf + A.FCourseSalePerf
|
|
|
|
|
FROM #PerfTotal AS A
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD> = <EFBFBD><EFBFBD>Ʒ+<EFBFBD><EFBFBD>Ŀ,<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>= <EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ʒ,<EFBFBD><EFBFBD>Ŀ֮<EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>=ָ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>/<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
DECLARE @Value VARCHAR(5)
|
|
|
|
|
EXEC PGetBizParameter @CompId,'EmpLaborPerfIncludeGoods',@Value OUTPUT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FPerfTotal = A.FGoodsPerf + A.FItemPerfTotal + A.FMemSalePerf,
|
|
|
|
|
A.FLaborPerf = CASE WHEN ISNULL(@Value,'True') = 'True' THEN A.FGoodsPerf ELSE 0 END + A.FItemPerfTotal, --<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʒ
|
|
|
|
|
A.FDM1Rate = CASE WHEN A.FItemPerfTotal = 0 THEN 0 ELSE A.FItemDM1Perf / A.FItemPerfTotal END
|
|
|
|
|
FROM #PerfTotal AS A
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FCashAmtTotal = B.FAmt,
|
|
|
|
|
A.FCashPerfTotal = B.FPerf
|
|
|
|
|
FROM #PerfTotal AS A,(SELECT FEmpId,SUM(FAmt) AS FAmt,SUM(CASE WHEN @ShowAmt = 1 THEN FAmt ELSE FPerf END ) AS FPerf FROM #EmpPerfDetail WHERE FPayTypeId IN(0,1,2) GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FCommTotal = B.FComm
|
|
|
|
|
FROM #PerfTotal AS A,(SELECT FEmpId,SUM(FComm) AS FComm FROM #EmpPerfDetail GROUP BY FEmpId) AS B
|
|
|
|
|
WHERE A.FEmpId = B.FEmpId
|
|
|
|
|
|
|
|
|
|
SELECT FEmpNo + '-' + FEmpName AS EmpInfo,
|
|
|
|
|
FEmpNo AS EmpNo,
|
|
|
|
|
FItemPerfTotal AS ItemPerfTotal, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCustQty AS CustQty, --<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FPerfTotal AS PerfTotal, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM1Qty AS ItemDM1Qty, --ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM2Qty AS ItemDM2Qty, --<EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM3Qty AS ItemDM3Qty, --<EFBFBD><EFBFBD>ʽ3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM4Qty AS ItemDM4Qty, --<EFBFBD><EFBFBD>ʽ4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM1Perf AS ItemDM1Perf, --ָ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM2Perf AS ItemDM2Perf, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM3Perf AS ItemDM3Perf, --<EFBFBD><EFBFBD>ʽ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemDM4Perf AS ItemDM4Perf, --<EFBFBD><EFBFBD>ʽ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType1Perf AS WorkType1Perf, --<EFBFBD><EFBFBD>λ1ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType2Perf AS WorkType2Perf, --<EFBFBD><EFBFBD>λ2ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType3Perf AS WorkType3Perf, --<EFBFBD><EFBFBD>λ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FWorkType4Perf AS WorkType4Perf, --<EFBFBD><EFBFBD>λ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FGoodsPerf AS GoodsPerf, --<EFBFBD><EFBFBD>Ʒҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCourseSalePerf AS CourseSalePerf, --<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCardSalePerf AS CardSalePerf, --<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FMemSalePerf AS MemSalePerf, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FLaborPerf AS LaborPerf, --<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfCashPay AS ItemPerfCashPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfCardPay AS ItemPerfCardPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FItemPerfOtherPay AS ItemPerfOtherPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashPerfTotal AS CashPerfTotal, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FCashAmtTotal AS CashAmtTotal, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
FDM1Rate AS DM1Rate, --<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
|
|
|
|
FSanction AS Sanction, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FCommTotal AS CommTotal --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FROM #PerfTotal
|
|
|
|
|
WHERE FCustQty != 0 OR FPerfTotal != 0 OR FCommTotal != 0 OR FCashPerfTotal != 0 OR FMemSalePerf != 0 OR FGoodsPerf != 0
|
|
|
|
|
ORDER BY FEmpNo
|
|
|
|
|
|
|
|
|
|
SELECT '' AS EmpInfo,
|
|
|
|
|
SUM(FItemPerfTotal) AS ItemPerfTotal, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCustQty) AS CustQty, --<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FPerfTotal) AS PerfTotal, --<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM1Qty) AS ItemDM1Qty, --ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM2Qty) AS ItemDM2Qty, --<EFBFBD><EFBFBD><EFBFBD>ƿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM3Qty) AS ItemDM3Qty, --<EFBFBD><EFBFBD>ʽ3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM4Qty) AS ItemDM4Qty, --<EFBFBD><EFBFBD>ʽ4<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM1Perf) AS ItemDM1Perf, --ָ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM2Perf) AS ItemDM2Perf, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM3Perf) AS ItemDM3Perf, --<EFBFBD><EFBFBD>ʽ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemDM4Perf) AS ItemDM4Perf, --<EFBFBD><EFBFBD>ʽ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FWorkType1Perf) AS WorkType1Perf, --<EFBFBD><EFBFBD>λ1ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FWorkType2Perf) AS WorkType2Perf, --<EFBFBD><EFBFBD>λ2ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FWorkType3Perf) AS WorkType3Perf, --<EFBFBD><EFBFBD>λ3ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FWorkType4Perf) AS WorkType4Perf, --<EFBFBD><EFBFBD>λ4ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FGoodsPerf) AS GoodsPerf, --<EFBFBD><EFBFBD>Ʒҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCourseSalePerf) AS CourseSalePerf, --<EFBFBD>Ƴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCardSalePerf) AS CardSalePerf, --<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FMemSalePerf) AS MemSalePerf, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FLaborPerf) AS LaborPerf, --<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemPerfCashPay) AS ItemPerfCashPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemPerfCardPay) AS ItemPerfCardPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FItemPerfOtherPay) AS ItemPerfOtherPay, --<EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCashPerfTotal) AS CashPerfTotal, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCashAmtTotal) AS CashAmtTotal, --<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>Ӫҵ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FDM1Rate) AS DM1Rate, --<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FSanction) AS Sanction, --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SUM(FCommTotal) AS CommTotal --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
FROM #PerfTotal
|
|
|
|
|
WHERE FCustQty != 0 OR FPerfTotal != 0 OR FCommTotal != 0 OR FCashPerfTotal != 0 OR FMemSalePerf != 0 OR FGoodsPerf != 0
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptPadWageReport04','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptPadWageReport04
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE dbo.PRptPadWageReport04
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
DECLARE @FromDate VARCHAR(20)
|
|
|
|
|
DECLARE @ToDate VARCHAR(20)
|
|
|
|
|
DECLARE @EmpNo VARCHAR(20)
|
|
|
|
|
DECLARE @Version VARCHAR(20)
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = dbo.FNGetParamCompId(@IParam)
|
|
|
|
|
|
|
|
|
|
SELECT @FromDate = dbo.FNGetParamValue(@IParam,'FromDate')
|
|
|
|
|
SELECT @ToDate = dbo.FNGetParamValue(@IParam,'ToDate')
|
|
|
|
|
|
|
|
|
|
IF ISDATE(@FromDate) != 1 OR ISDATE(@ToDate) != 1
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
SELECT @FromDate = CONVERT(varchar(100),CAST(@FromDate AS DATETIME), 23)
|
|
|
|
|
SELECT @ToDate = CONVERT(varchar(100), CAST(@ToDate AS DATETIME), 23)
|
|
|
|
|
SELECT @EmpNo = dbo.FNGetParamValue(@IParam,'EmpNo')
|
|
|
|
|
SELECT @Version = dbo.FNGetParamValue(@IParam,'Version')
|
|
|
|
|
|
|
|
|
|
IF @CompId = 0 OR @FromDate IS NULL OR @ToDate IS NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
DECLARE @AllCompany BIT
|
|
|
|
|
SELECT @AllCompany = 0
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @EmpId BIGINT
|
|
|
|
|
SELECT @EmpId = FId FROM TEmployee WITH(NOLOCK) WHERE FNo = @EmpNo
|
|
|
|
|
|
|
|
|
|
INSERT #Company SELECT @CompId
|
|
|
|
|
|
|
|
|
|
EXEC PGenerateEmpPerf @AllCompany,@FromDate,@ToDate
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> #PerfDetail
|
|
|
|
|
SELECT A.*
|
|
|
|
|
INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A,#Company AS C
|
|
|
|
|
WHERE A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
AND C.FCompId = A.FCompId
|
|
|
|
|
AND A.FEmpId = @EmpId
|
|
|
|
|
AND A.FIsExpired = 0
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬<EFBFBD>㷨ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,@EmpId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ÿ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FBillId AS FBillId,
|
|
|
|
|
CASE WHEN (MIN(A.FCustGender)) = 1 THEN 'ItemMale' ELSE 'ItemFemale' END AS FCustGender, --<EFBFBD>ͻ<EFBFBD><EFBFBD>Ա<EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(CASE WHEN A.FDispatchMode = 10001 THEN 1 ELSE 2 END)) = 1
|
|
|
|
|
THEN 'ItemDMode1' ELSE 'ItemDMode2' END AS FDispatchMode--, --1ָ<EFBFBD><EFBFBD>,2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
-- 'Item' + MIN(A.FPayTypeCatg) AS FPayCatg --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INTO #ItemBill
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S WITH(NOLOCK) ON S.FId = A.FPayTypeId
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FBillId
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@Version,'') = '1'
|
|
|
|
|
BEGIN
|
|
|
|
|
CREATE TABLE #Total
|
|
|
|
|
(
|
|
|
|
|
Category VARCHAR(20),
|
|
|
|
|
Quantity DECIMAL(18,6),
|
|
|
|
|
PayAmt DECIMAL(18,6),
|
|
|
|
|
Perf DECIMAL(18,6),
|
|
|
|
|
Comm DECIMAL(18,6)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT '' AS FCagegory, COUNT(1) AS FQty, 0 AS FAmt ,0 AS Perf,0 AS Comm
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.Perf = B.FPerf
|
|
|
|
|
FROM #Total AS A, (SELECT SUM(FPerf) AS FPerf FROM EmpPerfDetail WHERE FCategory IN( 'Item','Goods')) AS B
|
|
|
|
|
WHERE Category = ''
|
|
|
|
|
|
|
|
|
|
--ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT FCategory AS FCagegory, ROUND(SUM(FSplitQuantity),2), ROUND(SUM(FAmt),2) AS FPayAmt,
|
|
|
|
|
ROUND(SUM(FPerf),2) AS FPerf,ROUND(SUM(FComm),2) AS FComm
|
|
|
|
|
FROM #PerfDetail
|
|
|
|
|
GROUP BY FCategory
|
|
|
|
|
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT 'Summary',SUM(Quantity),SUM(PayAmt),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Total
|
|
|
|
|
WHERE Category != ''
|
|
|
|
|
|
|
|
|
|
SELECT * FROM #Total
|
|
|
|
|
|
|
|
|
|
SELECT A.FCategory AS Category, A.FBillNo AS BillNo, A.FSplitQuantity AS Quantity, A.FAmt AS PayAmt,S.FName AS PayTypeName ,FDispatchMode AS DispatchMode,
|
|
|
|
|
A.FPerf AS Perf ,A.FComm AS Comm,A.FItemName AS ItemName ,REPLACE( CONVERT(varchar(100), FBillTime, 20),' ',CHAR(13) + CHAR(10)) AS BillTime
|
|
|
|
|
FROM #PerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S ON S.FId = A.FPayTypeId
|
|
|
|
|
ORDER BY A.FCategory , A.FBillTime
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT A.FEmpId AS EmpId, A.FCategory AS Category, A.FBillNo AS BillNo, A.FQuantity AS Quantity, A.FAmt AS Amt,
|
|
|
|
|
A.FPerf AS Perf ,A.FComm AS Comm,A.FItemName AS ItemName ,REPLACE( CONVERT(varchar(100), FBillTime, 20),' ',CHAR(10) + CHAR(13)) AS BillDate
|
|
|
|
|
FROM #PerfDetail AS A
|
|
|
|
|
ORDER BY A.FCategory , A.FBillTime
|
|
|
|
|
END
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptPadWageReport04','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptPadWageReport04
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE dbo.PRptPadWageReport04
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
DECLARE @FromDate VARCHAR(20)
|
|
|
|
|
DECLARE @ToDate VARCHAR(20)
|
|
|
|
|
DECLARE @EmpNo VARCHAR(20)
|
|
|
|
|
DECLARE @Version VARCHAR(20)
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = dbo.FNGetParamCompId(@IParam)
|
|
|
|
|
|
|
|
|
|
SELECT @FromDate = dbo.FNGetParamValue(@IParam,'FromDate')
|
|
|
|
|
SELECT @ToDate = dbo.FNGetParamValue(@IParam,'ToDate')
|
|
|
|
|
|
|
|
|
|
IF ISDATE(@FromDate) != 1 OR ISDATE(@ToDate) != 1
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
SELECT @FromDate = CONVERT(varchar(100),CAST(@FromDate AS DATETIME), 23)
|
|
|
|
|
SELECT @ToDate = CONVERT(varchar(100), CAST(@ToDate AS DATETIME), 23)
|
|
|
|
|
SELECT @EmpNo = dbo.FNGetParamValue(@IParam,'EmpNo')
|
|
|
|
|
SELECT @Version = dbo.FNGetParamValue(@IParam,'Version')
|
|
|
|
|
|
|
|
|
|
IF @CompId = 0 OR @FromDate IS NULL OR @ToDate IS NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
DECLARE @AllCompany BIT
|
|
|
|
|
SELECT @AllCompany = 0
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @EmpId BIGINT
|
|
|
|
|
SELECT @EmpId = FId FROM TEmployee WITH(NOLOCK) WHERE FNo = @EmpNo
|
|
|
|
|
|
|
|
|
|
INSERT #Company SELECT @CompId
|
|
|
|
|
|
|
|
|
|
EXEC PGenerateEmpPerf @AllCompany,@FromDate,@ToDate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> #EmpPerfDetail
|
|
|
|
|
SELECT A.*
|
|
|
|
|
INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A,#Company AS C
|
|
|
|
|
WHERE A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
AND C.FCompId = A.FCompId
|
|
|
|
|
AND A.FEmpId = @EmpId
|
|
|
|
|
AND A.FIsExpired = 0
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,@EmpId
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,ÿ<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.FBillId AS FBillId,
|
|
|
|
|
CASE WHEN (MIN(A.FCustGender)) = 1 THEN 'ItemMale' ELSE 'ItemFemale' END AS FCustGender, --<EFBFBD>ͻ<EFBFBD><EFBFBD>Ա<EFBFBD>
|
|
|
|
|
CASE WHEN (MIN(CASE WHEN A.FDispatchMode = 10001 THEN 1 ELSE 2 END)) = 1
|
|
|
|
|
THEN 'ItemDMode1' ELSE 'ItemDMode2' END AS FDispatchMode--, --1ָ<EFBFBD><EFBFBD>,2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
-- 'Item' + MIN(A.FPayTypeCatg) AS FPayCatg --֧<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 2 <EFBFBD>ֽ<EFBFBD>,1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>, 3<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INTO #ItemBill
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S WITH(NOLOCK) ON S.FId = A.FPayTypeId
|
|
|
|
|
WHERE FCategory = 'Item'
|
|
|
|
|
GROUP BY A.FBillId
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@Version,'') = '1'
|
|
|
|
|
BEGIN
|
|
|
|
|
CREATE TABLE #Total
|
|
|
|
|
(
|
|
|
|
|
Category VARCHAR(20),
|
|
|
|
|
Quantity DECIMAL(18,6),
|
|
|
|
|
PayAmt DECIMAL(18,6),
|
|
|
|
|
Perf DECIMAL(18,6),
|
|
|
|
|
Comm DECIMAL(18,6)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>ܿ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT '' AS FCagegory, COUNT(1) AS FQty, 0 AS FAmt ,0 AS Perf,0 AS Comm
|
|
|
|
|
FROM #ItemBill
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD>Ͷ<EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.Perf = B.FPerf
|
|
|
|
|
FROM #Total AS A, (SELECT SUM(FPerf) AS FPerf FROM #EmpPerfDetail WHERE FCategory IN( 'Item','Goods')) AS B
|
|
|
|
|
WHERE Category = ''
|
|
|
|
|
|
|
|
|
|
--ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT FCategory AS FCagegory, ROUND(SUM(FSplitQuantity),2), ROUND(SUM(FAmt),2) AS FPayAmt,
|
|
|
|
|
ROUND(SUM(FPerf),2) AS FPerf,ROUND(SUM(FComm),2) AS FComm
|
|
|
|
|
FROM #EmpPerfDetail
|
|
|
|
|
GROUP BY FCategory
|
|
|
|
|
|
|
|
|
|
INSERT #Total(Category,Quantity,PayAmt,Perf,Comm)
|
|
|
|
|
SELECT 'Summary',SUM(Quantity),SUM(PayAmt),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Total
|
|
|
|
|
WHERE Category != ''
|
|
|
|
|
|
|
|
|
|
SELECT * FROM #Total
|
|
|
|
|
|
|
|
|
|
SELECT A.FCategory AS Category, A.FBillNo AS BillNo, A.FSplitQuantity AS Quantity, A.FAmt AS PayAmt,S.FName AS PayTypeName ,FDispatchMode AS DispatchMode,
|
|
|
|
|
A.FPerf AS Perf ,A.FComm AS Comm,A.FItemName AS ItemName ,REPLACE( CONVERT(varchar(100), FBillTime, 20),' ',CHAR(13) + CHAR(10)) AS BillTime
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS S ON S.FId = A.FPayTypeId
|
|
|
|
|
ORDER BY A.FCategory , A.FBillTime
|
|
|
|
|
END
|
|
|
|
|
ELSE
|
|
|
|
|
BEGIN
|
|
|
|
|
SELECT A.FEmpId AS EmpId, A.FCategory AS Category, A.FBillNo AS BillNo, A.FQuantity AS Quantity, A.FAmt AS Amt,
|
|
|
|
|
A.FPerf AS Perf ,A.FComm AS Comm,A.FItemName AS ItemName ,REPLACE( CONVERT(varchar(100), FBillTime, 20),' ',CHAR(10) + CHAR(13)) AS BillDate
|
|
|
|
|
FROM #EmpPerfDetail AS A
|
|
|
|
|
ORDER BY A.FCategory , A.FBillTime
|
|
|
|
|
END
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF object_id('dbo.PRptWageReport01','P') IS NOT NULL
|
|
|
|
|
BEGIN
|
|
|
|
|
DROP PROCEDURE dbo.PRptWageReport01
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE PRptWageReport01
|
|
|
|
|
(
|
|
|
|
|
@IParam VARCHAR(8000)
|
|
|
|
|
)
|
|
|
|
|
AS
|
|
|
|
|
BEGIN
|
|
|
|
|
DECLARE @CompanyStr VARCHAR(8000)
|
|
|
|
|
DECLARE @FromDate CHAR(10)
|
|
|
|
|
DECLARE @ToDate CHAR(10)
|
|
|
|
|
DECLARE @IncChild CHAR
|
|
|
|
|
DECLARE @CashierId BIGINT
|
|
|
|
|
DECLARE @DeptId BIGINT
|
|
|
|
|
DECLARE @AllCompany BIT
|
|
|
|
|
DECLARE @PayTypeNo VARCHAR(1000)
|
|
|
|
|
DECLARE @ItemNo VARCHAR(1000)
|
|
|
|
|
DECLARE @DeptNo VARCHAR(1000)
|
|
|
|
|
DECLARE @CompId BIGINT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT @CompanyStr = dbo.FNGetParamValue(@IParam,'Company')
|
|
|
|
|
SELECT @FromDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'FromDate'),23)
|
|
|
|
|
SELECT @ToDate = CONVERT(CHAR(10),dbo.FNGetParamValue(@IParam,'ToDate'),23)
|
|
|
|
|
SELECT @PayTypeNo = ISNULL(dbo.FNGetParamValue(@IParam,'PayTypeNo'),'')
|
|
|
|
|
SELECT @ItemNo = ISNULL(dbo.FNGetParamValue(@IParam,'ItemNo'),'')
|
|
|
|
|
SELECT @DeptNo = ISNULL(dbo.FNGetParamValue(@IParam,'DeptNo'),'')
|
|
|
|
|
|
|
|
|
|
IF ISNULL(@ToDate,'') = '' OR ISNULL(@FromDate,'') = '' OR @FromDate > @ToDate
|
|
|
|
|
BEGIN
|
|
|
|
|
RETURN
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
CREATE TABLE #Company
|
|
|
|
|
(
|
|
|
|
|
FCompId BIGINT,
|
|
|
|
|
FCompNo VARCHAR(20)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INSERT #Company
|
|
|
|
|
SELECT A.FId,A.FNo
|
|
|
|
|
FROM TCompany AS A WITH(NOLOCK), dbo.FNStrSplit(@CompanyStr) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
|
|
|
|
|
SELECT @CompId = FCompId FROM #Company
|
|
|
|
|
|
|
|
|
|
IF @DeptNo = '' OR @DeptNo = '*'
|
|
|
|
|
BEGIN
|
|
|
|
|
SET @DeptId = 0
|
|
|
|
|
END
|
|
|
|
|
SELECT @DeptId = FId FROM TBasicType WITH(NOLOCK) WHERE FKey = 'Department' AND FNo = @DeptNo
|
|
|
|
|
|
|
|
|
|
DECLARE @PayTypeIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FPayTypeId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @ItemIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FItemId BIGINT
|
|
|
|
|
)
|
|
|
|
|
DECLARE @CourseIds TABLE
|
|
|
|
|
(
|
|
|
|
|
FCourseId BIGINT
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IF @PayTypeNo != ''
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT @PayTypeIds(FPayTypeId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TPayAccount AS A WITH(NOLOCK), dbo.FNStrSplit(@PayTypeNo) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
IF @ItemNo != ''
|
|
|
|
|
BEGIN
|
|
|
|
|
INSERT @ItemIds(FItemId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TItem AS A WITH(NOLOCK), dbo.FNStrSplit(@ItemNo) AS B
|
|
|
|
|
WHERE A.FNo = B.Field
|
|
|
|
|
|
|
|
|
|
INSERT @CourseIds(FCourseId)
|
|
|
|
|
SELECT A.FId
|
|
|
|
|
FROM TCourse AS A WITH(NOLOCK) ,@ItemIds AS B
|
|
|
|
|
WHERE A.FItemId = B.FItemId
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SET @AllCompany = 0
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>#Company <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PGenerateEmpPerf @AllCompany,@FromDate,@ToDate
|
|
|
|
|
|
|
|
|
|
/* SELECT A.FId AS FEmpId , A.FNo FEmpNo, A.FName AS FEmpName, CAST(A.FPosId AS VARCHAR(20)) AS FPosId
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK)
|
|
|
|
|
INNER JOIN #Company AS C on c.FCompId = a.FCompId
|
|
|
|
|
|
|
|
|
|
UNION ALL */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT A.FId AS FEmpId, A.FNo AS FEmpNo,A.FName AS FEmpName, CAST(A.FPosId AS VARCHAR(20)) AS PosId
|
|
|
|
|
INTO #Employee
|
|
|
|
|
FROM TEmployee AS A WITH(NOLOCK)
|
|
|
|
|
INNER JOIN TEmployeeSub AS B ON B.FEmpId = A.FId
|
|
|
|
|
INNER JOIN #Company AS C ON C.FCompId = B.FCompId
|
|
|
|
|
WHERE (@DeptId = 0 OR A.FDeptId = @DeptId)
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>浽<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|
|
|
|
SELECT A.* INTO #EmpPerfDetail
|
|
|
|
|
FROM TEmpPerfDetail# AS A WITH(NOLOCK),#Employee AS E
|
|
|
|
|
WHERE A.FIsExpired = 0
|
|
|
|
|
AND A.FEmpId = E.FEmpId
|
|
|
|
|
AND A.FCompId = @CompId
|
|
|
|
|
AND A.FWorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>㶯̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
EXEC PCalcDynamicEmpComm @CompId,0
|
|
|
|
|
|
|
|
|
|
SELECT E.FEmpId AS EmpId, E.FEmpNo AS EmpNo, A.FCategory AS Category, FBillNo AS BillNo,FBillDetailId AS BillDetailId,
|
|
|
|
|
CONVERT(varchar(20),A.FBillTime, 120) AS BillTime,FWorkDate AS WorkDate, FWorkType AS WorkType,FDispatchMode AS DispatchMode, S.FName AS DispatchModeName,
|
|
|
|
|
FItemNo AS ItemNo, FItemNo + '-' + FItemName AS ItemName, FQuantity AS Quantity, P.FName AS PayTypeName, A.FPayTypeId AS PayTypeId,
|
|
|
|
|
FAmt AS PayAmt, FPerf AS Perf,FComm AS Comm,FDedCostPerf AS DedCostPerf,
|
|
|
|
|
CASE WHEN A.FCategory = 'Item' THEN S2.FName WHEN A.FCategory = 'Goods' THEN S4.FName ELSE S3.FName END AS WorkTypeName,
|
|
|
|
|
A.FMemNo AS MemNo,ISNULL(A.FCustName,M.FName) AS CustName, A.FCardNo AS CardNo, CASE WHEN ISNULL(FCustGender,M.FGender) = 1 THEN '<EFBFBD><EFBFBD>' ELSE 'Ů' END AS CustGender,
|
|
|
|
|
CT.FName AS CardTypeName
|
|
|
|
|
INTO #PerfDetail
|
|
|
|
|
FROM #Employee AS E, #EmpPerfDetail AS A
|
|
|
|
|
LEFT JOIN TBasicType AS S WITH(NOLOCK) ON S.FKey = 'ServeDispatchMode' AND S.FId = A.FDispatchMode
|
|
|
|
|
LEFT JOIN TBasicType AS S2 WITH(NOLOCK) ON S2.FKey = 'ServeWorkType' AND S2.FId = A.FWorkType AND A.FCategory = 'Item'
|
|
|
|
|
LEFT JOIN TBasicType AS S3 WITH(NOLOCK) ON S3.FKey = 'MemSaleWorkType' AND S3.FId = A.FWorkType AND A.FCategory IN('CardSale','CardRchg','CourseSale','CoursePackSale')
|
|
|
|
|
LEFT JOIN TBasicType AS S4 WITH(NOLOCK) ON S4.FKey = 'GoodsSaleWorkType' AND S4.FId = A.FWorkType AND A.FCategory IN('Goods')
|
|
|
|
|
LEFT JOIN TMember AS M WITH(NOLOCK) ON A.FMemId = M.FMemId
|
|
|
|
|
LEFT JOIN TPayAccount AS P ON P.FId = A.FPayTypeId
|
|
|
|
|
LEFT JOIN TMemberCardType AS CT ON CT.FId = A.FCardTypeId
|
|
|
|
|
WHERE E.FEmpId = A.FEmpId
|
|
|
|
|
AND (@PayTypeNo = '' OR A.FPayTypeId IN(SELECT FPayTypeId FROM @PayTypeIds))
|
|
|
|
|
AND (@ItemNo = '' OR (A.FCategory = 'Item' AND A.FItemId IN(SELECT FItemId FROM @ItemIds) )
|
|
|
|
|
OR (A.FCategory = 'CourseSale' AND A.FItemId IN(SELECT FCourseId FROM @CourseIds) ))
|
|
|
|
|
|
|
|
|
|
ORDER BY A.FEmpId,CASE WHEN A.FCategory IN('CardSale','CardRchg') THEN 1 WHEN A.FCategory IN( 'CourseSale','CoursePackSale') THEN 2
|
|
|
|
|
WHEN A.FCategory = 'Goods' THEN 3 WHEN A.FCategory = 'Item' THEN 4 ELSE 5 END
|
|
|
|
|
,FBillTime, FBillNo,FBillDetailId,FWorkType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT FEmpNo AS EmpNo, FEmpName AS EmpName
|
|
|
|
|
FROM #Employee AS B
|
|
|
|
|
WHERE EXISTS(SELECT TOP 1 1 FROM #PerfDetail AS A WHERE A.EmpId = B.FEmpId)
|
|
|
|
|
ORDER BY FEmpNo
|
|
|
|
|
|
|
|
|
|
SELECT * FROM #PerfDetail
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
SELECT A.EmpId, A.Category ,SumType = CAST('Pay' AS VARCHAR(10)),PayTypeId,
|
|
|
|
|
SUM(A.PayAmt) AS PayAmt,SUM(DedCostPerf) AS DedCostPerf,SUM(A.Perf) AS Perf,SUM(A.Comm) AS Comm ,CAST(0 AS DECIMAL(18,6)) AS Quantity
|
|
|
|
|
INTO #Summary
|
|
|
|
|
FROM #PerfDetail AS A,#Employee AS E--,#Company AS C
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
-- AND A.CompId = C.FCompId
|
|
|
|
|
AND A.WorkDate BETWEEN @FromDate AND @ToDate
|
|
|
|
|
-- AND A.FIsExpired = 0
|
|
|
|
|
-- AND (@PayTypeNo = '' OR A.FPayTypeId IN(SELECT FPayTypeId FROM @PayTypeIds))
|
|
|
|
|
-- AND (@ItemNo = '' OR (A.FCategory = 'Item' AND A.FItemId IN(SELECT FItemId FROM @ItemIds) ))
|
|
|
|
|
GROUP BY A.EmpId, A.Category ,A.PayTypeId
|
|
|
|
|
|
|
|
|
|
INSERT #Summary(EmpId,Category,SumType,PayAmt,DedCostPerf,Perf,Comm)
|
|
|
|
|
SELECT EmpId,Category, 'Total',SUM(PayAmt),SUM(DedCostPerf),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Summary
|
|
|
|
|
GROUP BY EmpId,Category
|
|
|
|
|
|
|
|
|
|
INSERT #Summary(EmpId,Category,SumType,PayAmt,DedCostPerf,Perf,Comm)
|
|
|
|
|
SELECT EmpId,'All', 'Total',SUM(PayAmt),SUM(DedCostPerf),SUM(Perf),SUM(Comm)
|
|
|
|
|
FROM #Summary
|
|
|
|
|
WHERE SumType = 'Total'
|
|
|
|
|
GROUP BY EmpId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.Quantity = T2.Quantity
|
|
|
|
|
FROM #Summary AS A,
|
|
|
|
|
(
|
|
|
|
|
SELECT EmpId,Category,SUM(Quantity) AS Quantity
|
|
|
|
|
FROM
|
|
|
|
|
(
|
|
|
|
|
SELECT A.EmpId,Category,1 AS Quantity
|
|
|
|
|
FROM #PerfDetail AS A,#Employee AS E,#Company AS C
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
|
|
|
|
|
GROUP BY A.EmpId,A.Category,A.BillNo,A.BillDetailId,A.WorkType
|
|
|
|
|
) AS T GROUP BY T.EmpId,Category
|
|
|
|
|
) AS T2
|
|
|
|
|
WHERE T2.Category = A.Category
|
|
|
|
|
AND T2.EmpId = A.EmpId
|
|
|
|
|
AND A.SumType = 'Total'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SELECT E.FEmpNo AS EmpNo,A.Category AS Category, A.SumType AS SumType, ISNULL(P.FName,'') AS PayTypeName,
|
|
|
|
|
ISNULL(A.PayAmt,0) AS PayAmt,ISNULL(A.Perf,0) AS Perf,ISNULL(A.DedCostPerf,0) AS DedCostPerf,ISNULL(A.Quantity,0) AS Quantity,ISNULL(A.Comm,0) AS Comm
|
|
|
|
|
FROM #Employee AS E,#Summary AS A
|
|
|
|
|
LEFT JOIN TPayAccount AS P ON P.FId = A.PayTypeId
|
|
|
|
|
WHERE A.EmpId = E.FEmpId
|
|
|
|
|
ORDER BY CASE WHEN ISNULL(P.FNo,'') = '' THEN '<EFBFBD><EFBFBD>' ELSE P.FNo END
|
|
|
|
|
|
|
|
|
|
END
|
|
|
|
|
GO
|
|
|
|
|
|