join dc_semi_stock_sales_shipping t2 on t2.warehouse_name=t1.warehouse_name and t1.bailun_sku=t2.sku
set t1.quantity_purchase=t2.on_the_way_count,t1.purchase_amount=t2.on_the_way_amount,t1.oneday_total_sales=t2.sales_1,t1.amount_onedaysale=t2.stock_amount_1,t1.sevenday_total_sales=t2.sales_7,t1.fourteenday_total_sales=t2.sales_14,t1.thirtyday_total_sales=t2.sales_30,t1.nostockcount=t2.out_of_stock,t1.noshippingcount=t2.need_quantity,t1.quantity_tuneout_30days=t2.out_stock_30,t1.quantity_tunein_30days=t2.put_stock_30;";
cn.Execute("update dc_skuwarehouse_stock_sales set cash_in_30days=0,cash_out_30days=0,cash_net = 0");
varsql=@"update dc_skuwarehouse_stock_sales t1
join dc_base_stock t2 on (t2.pay_amount_30>0 or t2.income_amount_30>0) and t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code
set t1.cash_in_30days=t2.income_amount_30,t1.cash_out_30days=t2.pay_amount_30,t1.cash_net = t2.income_amount_30-t2.pay_amount_30";
varlist=cn.Query<mCash>("select t2.bailun_sku,t2.warehouse_code,t2.pay_amount_30,t2.income_amount_30 from dc_base_stock t2 where (t2.pay_amount_30>0 or t2.income_amount_30>0)");
foreach(variteminlist)
{
cn.Execute("update dc_skuwarehouse_stock_sales set cash_in_30days="+item.income_amount_30+",cash_out_30days="+item.pay_amount_30+",cash_net="+(item.income_amount_30-item.pay_amount_30)+" where bailun_sku='"+item.bailun_sku+"' and warehouse_code='"+item.warehouse_code+"'");
sum(case when t1.available_days<15 then 1 else 0 end) as less15days_skucount,
sum(case when t1.available_days<15 then t1.usable_stock+t1.occupy_stock else 0 end) as less15days,
sum(case when t1.available_days<15 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as less15days_amount,
sum(case when t1.available_days>=15 and t1.available_days<30 then 1 else 0 end) as fifteen_30_days_skucount,
sum(case when t1.available_days>=15 and t1.available_days<30 then t1.usable_stock+t1.occupy_stock else 0 end) as fifteen_30_days,
sum(case when t1.available_days>=15 and t1.available_days<30 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as fifteen_30_days_amount,
sum(case when t1.available_days>=30 and t1.available_days<45 then 1 else 0 end) as thirty_45_days_skucount,
sum(case when t1.available_days>=30 and t1.available_days<45 then t1.usable_stock+t1.occupy_stock else 0 end) as thirty_45_days,
sum(case when t1.available_days>=30 and t1.available_days<45 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as thirty_45_days_amount,
sum(case when t1.available_days>=45 and t1.available_days<60 then 1 else 0 end) as fortyfive_60_days_skucount,
sum(case when t1.available_days>=45 and t1.available_days<60 then t1.usable_stock+t1.occupy_stock else 0 end) as fortyfive_60_days,
sum(case when t1.available_days>=45 and t1.available_days<60 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as fortyfive_60_days_amount,
sum(case when t1.available_days>=60 and t1.available_days<90 then 1 else 0 end) as sixty_90_days_skucount,
sum(case when t1.available_days>=60 and t1.available_days<90 then t1.usable_stock+t1.occupy_stock else 0 end) as sixty_90_days,
sum(case when t1.available_days>=60 and t1.available_days<90 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as sixty_90_days_amount,
sum(case when t1.available_days>=90 and t1.available_days<120 then 1 else 0 end) as ninty_120_days_skucount,
sum(case when t1.available_days>=90 and t1.available_days<120 then t1.usable_stock+t1.occupy_stock else 0 end) as ninty_120_days,
sum(case when t1.available_days>=90 and t1.available_days<120 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as ninty_120_days_amount,
sum(case when t1.available_days>=120 and t1.available_days<180 then 1 else 0 end) as onetwozero_180_days_skucount,
sum(case when t1.available_days>=120 and t1.available_days<180 then t1.usable_stock+t1.occupy_stock else 0 end) as onetwozero_180_days,
sum(case when t1.available_days>=120 and t1.available_days<180 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as onetwozero_180_days_amount,
sum(case when t1.available_days>=180 then 1 else 0 end) as morethen_180_days_skucount,
sum(case when t1.available_days>=180 then t1.usable_stock+t1.occupy_stock else 0 end) as morethen_180_days,
sum(case when t1.available_days>=180 then (t1.usable_stock+t1.occupy_stock)*t2.unit_price else 0 end) as morethen_180_days_amount
from dc_base_stock t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.available_days>0 and t1.warehouse_code='{warehouse_code}'
group by t1.warehouse_code";
}
elseif(isfinish==0)//半成品
{
sql=$@"select t1.warehouse_id as warehouse_code,
sum(case when t1.available_days<15 then 1 else 0 end) as less15days_skucount,
sum(case when t1.available_days<15 then t1.stock else 0 end) as less15days,
sum(case when t1.available_days<15 then (t1.stock)*t1.buyer_price else 0 end) as less15days_amount,
sum(case when t1.available_days>=15 and t1.available_days<30 then 1 else 0 end) as fifteen_30_days_skucount,
sum(case when t1.available_days>=15 and t1.available_days<30 then t1.stock else 0 end) as fifteen_30_days,
sum(case when t1.available_days>=15 and t1.available_days<30 then (t1.stock)*t1.buyer_price else 0 end) as fifteen_30_days_amount,
sum(case when t1.available_days>=30 and t1.available_days<45 then 1 else 0 end) as thirty_45_days_skucount,
sum(case when t1.available_days>=30 and t1.available_days<45 then t1.stock else 0 end) as thirty_45_days,
sum(case when t1.available_days>=30 and t1.available_days<45 then (t1.stock)*t1.buyer_price else 0 end) as thirty_45_days_amount,
sum(case when t1.available_days>=45 and t1.available_days<60 then 1 else 0 end) as fortyfive_60_days_skucount,
sum(case when t1.available_days>=45 and t1.available_days<60 then t1.stock else 0 end) as fortyfive_60_days,
sum(case when t1.available_days>=45 and t1.available_days<60 then (t1.stock)*t1.buyer_price else 0 end) as fortyfive_60_days_amount,
sum(case when t1.available_days>=60 and t1.available_days<90 then 1 else 0 end) as sixty_90_days_skucount,
sum(case when t1.available_days>=60 and t1.available_days<90 then t1.stock else 0 end) as sixty_90_days,
sum(case when t1.available_days>=60 and t1.available_days<90 then (t1.stock)*t1.buyer_price else 0 end) as sixty_90_days_amount,
sum(case when t1.available_days>=90 and t1.available_days<120 then 1 else 0 end) as ninty_120_days_skucount,
sum(case when t1.available_days>=90 and t1.available_days<120 then t1.stock else 0 end) as ninty_120_days,
sum(case when t1.available_days>=90 and t1.available_days<120 then (t1.stock)*t1.buyer_price else 0 end) as ninty_120_days_amount,
sum(case when t1.available_days>=120 and t1.available_days<180 then 1 else 0 end) as onetwozero_180_days_skucount,
sum(case when t1.available_days>=120 and t1.available_days<180 then t1.stock else 0 end) as onetwozero_180_days,
sum(case when t1.available_days>=120 and t1.available_days<180 then (t1.stock)*t1.buyer_price else 0 end) as onetwozero_180_days_amount,
sum(case when t1.available_days>=180 then 1 else 0 end) as morethen_180_days_skucount,
sum(case when t1.available_days>=180 then t1.stock else 0 end) as morethen_180_days,
sum(case when t1.available_days>=180 then (t1.stock)*t1.buyer_price else 0 end) as morethen_180_days_amount
from dc_semi_stock_sales_shipping t1
where t1.available_days>0 and t1.warehouse_id={warehouse_code}