CREATE PROCEDURE  [dbo].[spDataCaptureFactorItems] @TypeOperation TINYINT, @Autoid BIGINT, @UserId Smallint 
AS

IF @TypeOperation = 4 
BEGIN
Insert Into History_Detail_Factors (Id_Havaleh,AutoId,Sender,Reciver,Radif,K_Code,K_Qty1,
                                    K_Qty2,R_Unit1_2,Price_Kharid,Price_Forosh,Point_Flag,
                                    Serial_Flag,Hamrah_Flag,CtrMojodi,Exp_Flag,Make_Flag,Note,Status, UserIdForSelete, TransactionType)
SELECT Id_Havaleh,AutoId,Sender,Reciver,Radif,K_Code,K_Qty1,
                                    K_Qty2,R_Unit1_2,Price_Kharid,Price_Forosh,Point_Flag,
                                    Serial_Flag,Hamrah_Flag,CtrMojodi,Exp_Flag,Make_Flag,Note,'D', @UserId,3 FROM dbo.TmpHavaleh WITH (NOLOCK)
WHERE AutoId = @AutoId

END  
ELSE
BEGIN 
	Insert Into History_Detail_Factors (Id_Havaleh,AutoId,Sender,Reciver,Radif,K_Code,K_Qty1,
										K_Qty2,R_Unit1_2,Price_Kharid,Price_Forosh,Point_Flag,
										Serial_Flag,Hamrah_Flag,CtrMojodi,Exp_Flag,Make_Flag,Note,Status, UserIdForSelete, TransactionType)
	SELECT Id_Havaleh,AutoId,Sender,Reciver,Radif,K_Code,K_Qty1,
										K_Qty2,R_Unit1_2,Price_Kharid,Price_Forosh,Point_Flag,
										Serial_Flag,Hamrah_Flag,CtrMojodi,Exp_Flag,Make_Flag,Note,status, @UserId,@TypeOperation FROM dbo.Havaleh WITH (NOLOCK)
	WHERE AutoId = @AutoId
END 
    


