if exists(select 1 from sysobjects where name='pr_up_rm_saleflow')
  drop procedure pr_up_rm_saleflow
go

create procedure pr_up_rm_saleflow
(
   @flow_no varchar(18),
   @flow_id int,
   @branch_no varchar(6),
   @item_no varchar(20),
   @source_price numeric(16,4),
   @sale_price numeric(16,4),
   @cost_price numeric(16,4),
   @sale_qnty numeric(16,4),
   @sale_money numeric(16,4),
   @sell_way varchar(1),
   @oper_id	varchar(6),
   @sale_man varchar(6),
   @oper_date DateTime,
   @shift_no varchar(9),
   @spec_flag varchar(10),
   @pref_amt numeric(16,4),
   @in_price numeric(16,4),
   @acc_num numeric(16,4),
   @dec_rate numeric(16,4),
   @card_id varchar(20),
   @card_no varchar(20),
   @pro_id int,
   @clss_rate numeric(16,4),
   @Brand_rate numeric(16,4),
   @sale_rate numeric(16,4),
   @sale_duty_rate numeric(16,4),
   @outParam varchar(20) output
)
as  
begin
  --上传商品销售流水
   declare @temp_flow_no varchar(20)
   set @temp_flow_no=Replace(@flow_no,'T','')
   --liuw,150624预防重单数据没有上传上。单号一样，但是时间不一样。
   if   exists(select 1 from t_rm_saleflow where (flow_no=@flow_no or flow_no=@temp_flow_no) and flow_id=@flow_id 
				and branch_no=@branch_no and item_no=@item_no	and CONVERT(VARCHAR(19),oper_date,121)=CONVERT(VARCHAR(19),@oper_date,121))   
   begin 
      set @outParam=@flow_no
      DECLARE @MyTableVar table(flow_no varchar(20))
	  insert into @MyTableVar(flow_no) values('')
   end
   else
   begin
      insert into t_rm_saleflow(flow_no,flow_id,branch_no,item_no,source_price,sale_price,cost_price,sale_qnty,sale_money,sell_way,oper_id,sale_man,oper_date,shift_no,
                                spec_flag,pref_amt,in_price,acc_num,dec_rate,card_id,card_no,pro_id,clss_rate,Brand_rate,sale_rate,sale_duty_rate)
                         values(@flow_no,@flow_id,@branch_no,@item_no,@source_price,@sale_price,@cost_price,@sale_qnty,@sale_money,@sell_way,@oper_id,@sale_man,@oper_date,@shift_no,
                                @spec_flag,@pref_amt,@in_price,@acc_num,@dec_rate,@card_id,@card_no,@pro_id,@clss_rate,@Brand_rate,@sale_rate,@sale_duty_rate)
      set @outParam=''
   end
end
go
