varsql=$@"select sum(t2.end_onway_count) start_onway_count,sum(t2.end_stock_count) start_stock_count,sum(t2.end_onway_amount) start_onway_amount,sum(t2.end_stock_amount) start_stock_amount,sum(t3.end_onway_count) end_onway_count,sum(t3.end_stock_count) end_stock_count,sum(t3.end_onway_amount) end_onway_amount,sum(t3.end_stock_amount) end_stock_amount,sum(t4.end_stock_amount) as amount,sum(t4.end_stock_count) as count,sum(t3.end_stock_count-t2.end_stock_count) diff_stock_count,sum(t3.end_stock_amount-t2.end_stock_amount) diff_stock_amount,sum(t3.end_onway_count-t2.end_onway_count) diff_onway_count,sum(t3.end_onway_amount-t2.end_onway_amount) diff_onway_amount from (select DISTINCT t1.bailun_sku,t1.warehouse_code,t1.warehouse_name from dc_daily_purchase_sell_stock t1
...
...
@@ -3272,19 +3274,19 @@ group by currency";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
//sqlparam.Add("hq_type", warehousetype);
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t2.warehouse_code='"+warehouse+"'";
sql+=" and t2.warehouse_code='"+warehouse+"'";
//sqlparam.Add("warehouse", warehouse);
}
}
if(!string.IsNullOrEmpty(warehouse))
{
sql+=$@" where (t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') {(!string.IsNullOrEmpty(sku)?" and t1.bailun_sku='"+sku+"'":"")}) t1
sql+=$@" where (t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') {(!string.IsNullOrEmpty(sku)?" and t1.bailun_sku='"+sku+"'":"")}) t1
left join dc_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}' and t2.warehouse_code='{warehouse}'
left join dc_daily_purchase_sell_stock t3 on t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.record_time='{end.ToString("yyyy-MM-dd")}' and t2.warehouse_code='{warehouse}'";
varsql=$@"select t1.bailun_sku,t4.sku_title_cn,t1.warehouse_code,t1.warehouse_name,t2.end_onway_count as start_onway_count,t2.end_stock_count as start_stock_count,t2.end_onway_amount as start_onway_amount,t2.end_stock_amount as start_stock_amount,t3.end_onway_count,t3.end_stock_count,t3.end_onway_amount,t3.end_stock_amount,(if(t3.end_stock_count is null,0,t3.end_stock_count)-if(t2.end_stock_count is null,0,t2.end_stock_count)) diff_stock_count,(if(t3.end_stock_amount is null,0,t3.end_stock_amount)-if(t2.end_stock_amount is null,0,t2.end_stock_amount)) diff_stock_amount,(if(t3.end_onway_count is null,0,t3.end_onway_count)-if(t2.end_onway_count is null,0,t2.end_onway_count)) diff_onway_count,(if(t3.end_onway_amount is null,0,t3.end_onway_amount)-if(t2.end_onway_amount is null,0,t2.end_onway_amount)) diff_onway_amount,t5.end_stock_amount amount,t5.end_stock_count as count from
...
...
@@ -3344,13 +3346,13 @@ group by currency";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type=@hq_type";
sqlcount+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
sqlcount+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
sqlparam.Add("hq_type",warehousetype);
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t2.warehouse_code=@warehouse";
sqlcount+=" and t2.warehouse_code='"+warehouse+"'";
sqlcount+=" and t2.warehouse_code='"+warehouse+"'";
sqlparam.Add("warehouse",warehouse);
}
}
...
...
@@ -3396,7 +3398,7 @@ group by currency";
tb="t3.";
}
sql+=" order by "+tb+parameter.sort+" "+parameter.order;
sql+=" order by "+tb+parameter.sort+" "+parameter.order;
varsqlcount=$@"select count(DISTINCT t1.warehouse_code) from dc_semi_daily_purchase_sell_stock t1 ";
varsql=$@"select t1.warehouse_code,t1.warehouse_name,sum(t2.end_onway_count) start_onway_count,sum(t2.end_stock_count) start_stock_count,sum(t2.end_onway_amount) start_onway_amount,sum(t2.end_stock_amount) start_stock_amount,sum(t3.end_onway_count) end_onway_count,sum(t3.end_stock_count) end_stock_count,sum(t3.end_onway_amount) end_onway_amount,sum(t3.end_stock_amount) end_stock_amount,t4.end_stock_amount as amount,t4.end_stock_count as count,sum(if(t3.end_stock_count is null,0,t3.end_stock_count)-if(t2.end_stock_count is null,0,t2.end_stock_count)) diff_stock_count,sum(if(t3.end_stock_amount is null,0,t3.end_stock_amount)-if(t2.end_stock_amount is null,0,t2.end_stock_amount)) diff_stock_amount,sum(if(t3.end_onway_count is null,0,t3.end_onway_count)-if(t2.end_onway_count is null,0,t2.end_onway_count)) diff_onway_count,sum(if(t3.end_onway_amount is null,0,t3.end_onway_amount)-if(t2.end_onway_amount is null,0,t2.end_onway_amount)) diff_onway_amount from (select DISTINCT t1.bailun_sku,t1.warehouse_code,t1.warehouse_name from dc_semi_daily_purchase_sell_stock t1
";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
sqlcount+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
//sqlparam.Add("hq_type", warehousetype);
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t2.warehouse_code='"+warehouse+"'";
sqlcount+=" and t2.warehouse_code='"+warehouse+"'";
//sqlparam.Add("warehouse", warehouse);
}
}
if(!string.IsNullOrEmpty(warehouse))
{
sql+=$@" where t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') t1
left join dc_semi_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}' and t2.warehouse_code='{warehouse}'
left join dc_semi_daily_purchase_sell_stock t3 on t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.record_time='{end.ToString("yyyy-MM-dd")}' and t3.warehouse_code='{warehouse}'";
}
else
{
sql+=$@" where t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') t1
left join dc_semi_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}'
left join dc_semi_daily_purchase_sell_stock t3 on t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.record_time='{end.ToString("yyyy-MM-dd")}'";
}
sql+=$"left join (select t01.bailun_sku,t01.warehouse_code,sum((t01.end_stock_count-t01.start_stock_count)+(t01.end_onway_count-t01.start_onway_count)) end_stock_count,sum((t01.end_stock_amount-t01.start_stock_amount)+(t01.end_onway_amount-t01.start_onway_amount)) end_stock_amount from dc_semi_daily_purchase_sell_stock t01 ";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t02 on t01.warehouse_code=t02.warehouse_code and t02.hq_type='"+warehousetype+"'";
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t02.warehouse_code='"+warehouse+"'";
}
}
sql+=$" where t01.record_time>='{start.ToString("yyyy-MM-dd")}' and t01.record_time<='{end.ToString("yyyy-MM-dd")}' group by t01.bailun_sku,t01.warehouse_code) t4 on t1.bailun_sku=t4.bailun_sku and t4.warehouse_code=t1.warehouse_code";
sql+=" group by t1.warehouse_code ";
sqlcount+=$" where t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}'";
if(!string.IsNullOrEmpty(parameter.sort))
{
sql+=" order by "+parameter.sort+" "+parameter.order;
varsql=$@"select sum(t2.end_onway_count) start_onway_count,sum(t2.end_stock_count) start_stock_count,sum(t2.end_onway_amount) start_onway_amount,sum(t2.end_stock_amount) start_stock_amount,sum(t3.end_onway_count) end_onway_count,sum(t3.end_stock_count) end_stock_count,sum(t3.end_onway_amount) end_onway_amount,sum(t3.end_stock_amount) end_stock_amount,sum(t4.end_stock_amount) as amount,sum(t4.end_stock_count) as count,sum(t3.end_stock_count-t2.end_stock_count) diff_stock_count,sum(t3.end_stock_amount-t2.end_stock_amount) diff_stock_amount,sum(t3.end_onway_count-t2.end_onway_count) diff_onway_count,sum(t3.end_onway_amount-t2.end_onway_amount) diff_onway_amount from (select DISTINCT t1.bailun_sku,t1.warehouse_code,t1.warehouse_name from dc_semi_daily_purchase_sell_stock t1
";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
//sqlparam.Add("hq_type", warehousetype);
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t2.warehouse_code='"+warehouse+"'";
//sqlparam.Add("warehouse", warehouse);
}
}
if(!string.IsNullOrEmpty(warehouse))
{
sql+=$@" where (t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') {(!string.IsNullOrEmpty(sku)?" and t1.bailun_sku='"+sku+"'":"")}) t1
left join dc_semi_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}' and t2.warehouse_code='{warehouse}'
left join dc_semi_daily_purchase_sell_stock t3 on t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.record_time='{end.ToString("yyyy-MM-dd")}' and t2.warehouse_code='{warehouse}'";
}
else
{
sql+=$@" where (t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}'){(!string.IsNullOrEmpty(sku)?" and t1.bailun_sku='"+sku+"'":"")}) t1
left join dc_semi_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}'
left join dc_semi_daily_purchase_sell_stock t3 on t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.record_time='{end.ToString("yyyy-MM-dd")}'";
}
sql+=$"left join (select t01.bailun_sku,t01.warehouse_code,sum((t01.end_stock_count-t01.start_stock_count)+(t01.end_onway_count-t01.start_onway_count)) end_stock_count,sum((t01.end_stock_amount-t01.start_stock_amount)+(t01.end_onway_amount-t01.start_onway_amount)) end_stock_amount from dc_semi_daily_purchase_sell_stock t01 ";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t02 on t01.warehouse_code=t02.warehouse_code and t02.hq_type='"+warehousetype+"'";
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t02.warehouse_code='"+warehouse+"'";
}
}
sql+=$" where (t01.record_time>='{start.ToString("yyyy-MM-dd")}' and t01.record_time<='{end.ToString("yyyy-MM-dd")}') {(!string.IsNullOrEmpty(sku)?" and t01.bailun_sku='"+sku+"'":"")} group by t01.bailun_sku,t01.warehouse_code) t4 on t1.bailun_sku=t4.bailun_sku and t4.warehouse_code=t1.warehouse_code";
varsql=$@"select t1.bailun_sku,t4.sku_title_cn,t1.warehouse_code,t1.warehouse_name,t2.end_onway_count as start_onway_count,t2.end_stock_count as start_stock_count,t2.end_onway_amount as start_onway_amount,t2.end_stock_amount as start_stock_amount,t3.end_onway_count,t3.end_stock_count,t3.end_onway_amount,t3.end_stock_amount,(if(t3.end_stock_count is null,0,t3.end_stock_count)-if(t2.end_stock_count is null,0,t2.end_stock_count)) diff_stock_count,(if(t3.end_stock_amount is null,0,t3.end_stock_amount)-if(t2.end_stock_amount is null,0,t2.end_stock_amount)) diff_stock_amount,(if(t3.end_onway_count is null,0,t3.end_onway_count)-if(t2.end_onway_count is null,0,t2.end_onway_count)) diff_onway_count,(if(t3.end_onway_amount is null,0,t3.end_onway_amount)-if(t2.end_onway_amount is null,0,t2.end_onway_amount)) diff_onway_amount,t5.end_stock_amount amount,t5.end_stock_count as count from
(select DISTINCT t1.bailun_sku,t1.warehouse_code,t1.warehouse_name from dc_semi_daily_purchase_sell_stock t1
";
varsqlcount=$@"select count(*) from (select distinct t1.bailun_sku,t1.warehouse_code from dc_semi_daily_purchase_sell_stock t1 ";
if(!string.IsNullOrEmpty(warehousetype))
{
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type=@hq_type";
sqlcount+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.hq_type='"+warehousetype+"'";
sqlparam.Add("hq_type",warehousetype);
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t2.warehouse_code=@warehouse";
sqlcount+=" and t2.warehouse_code='"+warehouse+"'";
sqlparam.Add("warehouse",warehouse);
}
}
}
sql+=$" where (t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}') ";
if(!string.IsNullOrEmpty(sku))
{
sql+=" and t1.bailun_sku=@sku";
sqlparam.Add("sku",sku);
}
sql+=") t1";
sql+=$@" left join dc_semi_daily_purchase_sell_stock t2 on t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code and t2.record_time='{start.ToString("yyyy-MM-dd")}'
left join dc_semi_daily_purchase_sell_stock t3 on t1.bailun_sku = t3.bailun_sku and t1.warehouse_code = t3.warehouse_code and t3.record_time = '{end.ToString("yyyy-MM-dd")}'
left join dc_base_sku t4 on t1.bailun_sku = t4.bailun_sku ";
sql+=$"left join (select t01.bailun_sku,t01.warehouse_code,sum((t01.end_stock_count-t01.start_stock_count)+(t01.end_onway_count-t01.start_onway_count)) end_stock_count,sum((t01.end_stock_amount-t01.start_stock_amount)+(t01.end_onway_amount-t01.start_onway_amount)) end_stock_amount from dc_semi_daily_purchase_sell_stock t01 ";
if(!string.IsNullOrEmpty(warehousetype))
{
sql+=" join dc_base_warehouse t02 on t01.warehouse_code=t02.warehouse_code and t02.hq_type='"+warehousetype+"'";
if(!string.IsNullOrEmpty(warehouse))
{
sql+=" and t02.warehouse_code='"+warehouse+"'";
}
}
sql+=$" where (t01.record_time>='{start.ToString("yyyy-MM-dd")}' and t01.record_time<='{end.ToString("yyyy-MM-dd")}') {(!string.IsNullOrEmpty(sku)?" and t01.bailun_sku='"+sku+"'":"")} group by t01.bailun_sku,t01.warehouse_code) t5 on t1.bailun_sku=t5.bailun_sku and t5.warehouse_code=t1.warehouse_code";
sqlcount+=$" where t1.record_time='{start.ToString("yyyy-MM-dd")}' or t1.record_time='{end.ToString("yyyy-MM-dd")}' {(!string.IsNullOrEmpty(sku)?" and t1.bailun_sku='"+sku+"'":"")}) as tb";
if(!string.IsNullOrEmpty(parameter.sort))
{
vartb="";
if(parameter.sort.IndexOf("start")>=0)
{
tb="t2.";
}
elseif(parameter.sort.IndexOf("end")>=0)
{
tb="t3.";
}
sql+=" order by "+tb+parameter.sort+" "+parameter.order;
varobj=cn.Query<dc_semi_daily_purchase_sell_stock>("select warehouse_code,warehouse_name from dc_semi_daily_purchase_sell_stock group by warehouse_code");