varsql=@"select t0.warehouse_code,t0.warehouse_name,t0.bailun_sku,t0.quantity_begin_month_inventory,t0.quantity_purchase_transit,t0.quantity_transfer_transit,t0.quantity_purchase_inbound,t0.quantity_purchase_inbound*t0.purchase_price as purchase_inbound_amount,t0.quantity_transfer_inbound,t0.quantity_transfer_inbound*t0.purchase_price as transfer_inbound_amount,t0.quantity_damaged,t0.quantity_overflow,t0.quantity_sku_changed,t0.quantity_sales,t0.quantity_end_month_inventory,t0.turnover_rate,t0.turnover_date,t0.inv_age_0to1_month,t0.inv_age_1to3_month,t0.inv_age_3to6_month,t0.inv_age_6to12_month,t0.inv_age_1to2_year,t0.inv_age_2to3_year,t0.inv_age_gt3_year,t0.quantity_instant_inventory,t0.quantity_instant_inventory*t0.purchase_price as instant_inventory_amount,t0.month_total_exports,t0.month_total_exports*t0.purchase_price as exportamount,t0.quantity_inner_purchase,t0.purchase_price ";
varsqlwhere=@"from (
select* from dc_month_inventory where warehouse_name <> '' group by warehouse_code,bailun_sku having MAX(record_time)
) as t0 where 1 = 1 ";
if(!string.IsNullOrEmpty(sku))
{
sqlwhere+=(" and t0.bailun_sku=@sku");
sqlparam.Add("sku",sku);
}
if(!string.IsNullOrEmpty(warehouse))
{
sqlwhere+=(" and t0.warehouse_code=@warehouse");
sqlparam.Add("warehouse",warehouse);
}
if(month.HasValue)
{
varmonthEnd=month.Value.AddMonths(1);
sqlwhere+=(" and t0.record_time>=@monthstart and t0.record_time<@monthend");
sqlparam.Add("monthstart",month.Value);
sqlparam.Add("monthend",monthEnd);
}
if(!string.IsNullOrEmpty(parameter.sort))
{
sqlwhere+=" order by "+parameter.sort+" "+parameter.order;