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

create procedure pr_up_da_jxc_daysum(
@item_no varchar(20),
@oper_date varchar(10),
@branch_no varchar(6),
@cost_price numeric(16,4),
@init_qty numeric(16,4),
@init_amt numeric(16,4),
@init_amt2 numeric(16,4),
@avg_cost_amt numeric(16,4),
@avg_profit_amt numeric(16,4),
@pi_qty numeric(16,4),
@pi_amt numeric(16,4),
@so_qty numeric(16,4),
@so_amt numeric(16,4),
@mi_qty numeric(16,4),
@mi_amt numeric(16,4),
@mo_qty numeric(16, 4),
@mo_amt numeric(16, 4),
@di_qty numeric(16, 4),
@di_amt numeric(16, 4),
@do_qty numeric(16, 4),
@do_amt numeric(16, 4),
@pos_qty numeric(16, 4), 
@pos_amt numeric(16, 4),
@pos_ret_qty numeric(16, 4), 
@pos_ret_amt numeric(16, 4), 
@pos_send_qty numeric(16, 4), 
@pos_send_amt numeric(16, 4), 
@oo_qty numeric(16,4),
@oo_amt numeric(16,4),
@settle_qty numeric(16,4),
@settle_amt numeric(16,4),
@settle_amt2 numeric(16,4),
@cost_change_amt numeric(16,4),
@pos_dct_amt numeric(16,4),
@main_sup varchar(8),
@dec_rate numeric(16,4),
@so_price numeric(16,4),
@sale_price numeric(16,4),
@item_sup_flag char (1) , 
@sup_ly_rate numeric(16, 4), 
@flag char (1),
@outParam varchar(20) output 
)
as
begin
	--上传毛利表
	if not exists(select * from t_da_jxc_daysum with(nolock) where branch_no=@branch_no and item_no=@item_no and oper_date=@oper_date)
	begin
		--不存在插入
		insert into t_da_jxc_daysum(item_no,oper_date,branch_no,cost_price,init_qty,init_amt,init_amt2,avg_cost_amt,avg_profit_amt,pi_qty,pi_amt,so_qty,so_amt,mi_qty,mi_amt,mo_qty,mo_amt,di_qty,di_amt,do_qty,do_amt,pos_qty,pos_amt,pos_ret_qty,pos_ret_amt,pos_send_qty,pos_send_amt,oo_qty,oo_amt,settle_qty,settle_amt,settle_amt2,cost_change_amt,pos_dct_amt,main_sup,dec_rate,so_price,sale_price,item_sup_flag,sup_ly_rate,flag)
		values(@item_no,@oper_date,@branch_no,@cost_price,@init_qty,@init_amt,@init_amt2,@avg_cost_amt,@avg_profit_amt,@pi_qty,@pi_amt,@so_qty,@so_amt,@mi_qty,@mi_amt,@mo_qty,@mo_amt,@di_qty,@di_amt,@do_qty,@do_amt,@pos_qty,@pos_amt,@pos_ret_qty,@pos_ret_amt,@pos_send_qty,@pos_send_amt,@oo_qty,@oo_amt,@settle_qty,@settle_amt,@settle_amt2,@cost_change_amt,@pos_dct_amt,@main_sup,@dec_rate,@so_price,@sale_price,@item_sup_flag,@sup_ly_rate,@flag)
	end
	else
	begin
		update t_da_jxc_daysum
		set cost_price=@cost_price,
			init_qty=@init_qty,
			init_amt=@init_amt,
			init_amt2=@init_amt2,
			avg_cost_amt=@avg_cost_amt,
			avg_profit_amt=@avg_profit_amt,
			pi_qty=@pi_qty,
			pi_amt=@pi_amt,
			so_qty=@so_qty,
			so_amt=@so_amt,
			mi_qty=@mi_qty,
			mi_amt=@mi_amt,
			mo_qty=@mo_qty,
			mo_amt=@mo_amt,
			di_qty=@di_qty,
			di_amt=@di_amt,
			do_qty=@do_qty,
			do_amt=@do_amt,
			pos_qty=@pos_qty,
			pos_amt=@pos_amt,
			pos_ret_qty=@pos_ret_qty,
			pos_ret_amt=@pos_ret_amt,
			pos_send_qty=@pos_send_qty,
			pos_send_amt=@pos_send_amt,
			oo_qty=@oo_qty,
			oo_amt=@oo_amt,
			settle_qty=@settle_qty,
			settle_amt=@settle_amt,
			settle_amt2=@settle_amt2,
			cost_change_amt=@cost_change_amt,
			pos_dct_amt=@pos_dct_amt,
			main_sup=@main_sup,
			dec_rate=@dec_rate,
			so_price=@so_price,
			sale_price=@sale_price,
			item_sup_flag=@item_sup_flag,
			sup_ly_rate=@sup_ly_rate,
			flag=@flag
		where  branch_no=@branch_no and item_no=@item_no and oper_date=@oper_date
	end

	set @outParam=''
end 
go
