using(varcn=newMySqlConnection(Common.GlobalConfig.ConnectionString+"Allow User Variables=True;"))
try
{
{
if(cn.State==System.Data.ConnectionState.Closed)
using(varcn=newMySqlConnection(Common.GlobalConfig.ConnectionString+"Allow User Variables=True;"))
{
{
cn.Open();
if(cn.State==System.Data.ConnectionState.Closed)
}
{
cn.Open();
}
#region成品
#region成品
//成品
//成品
//先保存采购的
//先保存采购的
varsql=$@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t1.price) amount from dc_base_purchase t1
varsql=$@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t1.price) amount from dc_base_purchase t1
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
sql=$@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.bailun_sku_quantity_ordered) count,sum(t1.bailun_sku_quantity_ordered*t2.unit_price) amount from dc_base_oms_sku t1
sql=$@"select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.bailun_sku_quantity_ordered) count,sum(t1.bailun_sku_quantity_ordered*t2.unit_price) amount from dc_base_oms_sku t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
left join dc_base_warehouse t3 on t1.warehouse_code = t3.warehouse_code
where t1.has_delete=0 and t1.has_scalp=0 and t1.bailun_payment_status!='Canceled' and t1.paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.bailun_order_status!='Canceled' and t1.warehouse_code!=''
where t1.has_delete=0 and t1.has_scalp=0 and t1.bailun_payment_status!='Canceled' and t1.paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.bailun_order_status!='Canceled' and t1.warehouse_code!=''
sql=$@"select tb.warehouse_code,tb.warehouse_name,tb.bailun_sku,sum(count) count,sum(amount) amount from (select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.quantity_shipped) count,sum(t1.quantity_shipped*t2.unit_price) amount from dc_base_oms_pick t1
sql=$@"select tb.warehouse_code,tb.warehouse_name,tb.bailun_sku,sum(count) count,sum(amount) amount from (select t1.warehouse_code,t3.warehouse_name,t1.bailun_sku,sum(t1.quantity_shipped) count,sum(t1.quantity_shipped*t2.unit_price) amount from dc_base_oms_pick t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_warehouse t3 on t1.warehouse_code=t3.warehouse_code
left join dc_base_warehouse t3 on t1.warehouse_code=t3.warehouse_code
where t1.company_id=1 and t1.has_delete=0 and t1.shipping_status='TotalShipping' and t1.shipping_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
where t1.company_id=1 and t1.has_delete=0 and t1.shipping_status='TotalShipping' and t1.shipping_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
where t1.company_id=1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.bailun_order_status!='Canceled' and t1.has_scalp=0 and t1.has_delete=0 and t1.has_cancle=0 and platform_type='FBA'
where t1.company_id=1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.bailun_order_status!='Canceled' and t1.has_scalp=0 and t1.has_delete=0 and t1.has_cancle=0 and platform_type='FBA'
sql=$@"select t1.source_warehouse_code as warehouse_code,t3.warehouse_name,t1.bailun_sku,t1.count,t1.count*t2.unit_price from dc_base_transfer_complete t1
sql=$@"select t1.source_warehouse_code as warehouse_code,t3.warehouse_name,t1.bailun_sku,t1.count,t1.count*t2.unit_price from dc_base_transfer_complete t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_warehouse t3 on t1.source_warehouse_code=t3.warehouse_code
left join dc_base_warehouse t3 on t1.source_warehouse_code=t3.warehouse_code
where t1.create_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.deleted = 0
where t1.create_time >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time < '{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.deleted = 0
sql=$@"select t1.warehouse_code,t2.warehouse_name,t1.bailun_sku,t1.usable_stock,(t1.usable_stock*t3.unit_price) as stockAmount from dc_base_stock t1 left join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code left join dc_base_sku t3 on t1.bailun_sku=t3.bailun_sku where t1.bailun_sku='{item.bailun_sku}' and t1.warehouse_code='{item.warehouse_code}'";
sql=$@"select t1.warehouse_code,t2.warehouse_name,t1.bailun_sku,t1.usable_stock,(t1.usable_stock*t3.unit_price) as stockAmount from dc_base_stock t1 left join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code left join dc_base_sku t3 on t1.bailun_sku=t3.bailun_sku where t1.bailun_sku='{item.bailun_sku}' and t1.warehouse_code='{item.warehouse_code}'";
sql=$@"select t1.warehouse_code,t1.bailun_sku,t1.usable_stock,(t1.usable_stock*t1.unit_price) as stockAmount from dc_daily_stock t1 where t1.record_time='{start.AddDays(-1).ToString("yyyy-MM-dd")}' and t1.bailun_sku='{item.bailun_sku}' and t1.warehouse_code='{item.warehouse_code}'";
sql=$@"select t1.warehouse_code,t1.bailun_sku,t1.usable_stock,(t1.usable_stock*t1.unit_price) as stockAmount from dc_daily_stock t1 where t1.record_time='{start.AddDays(-1).ToString("yyyy-MM-dd")}' and t1.bailun_sku='{item.bailun_sku}' and t1.warehouse_code='{item.warehouse_code}'";
sql=$@"select sum(quantity_purchase) as count,sum(quantity_purchase*unit_price) as amount,bailun_sku,warehouse_from_code as warehouse_code,warehouse_from_name as warehouse_name from dc_semi_purchase_info where detail_delstatus=0 and create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and `status`>-1 and deliver_name !='广州哈倪蔓生物科技有限公司' and deliver_name!='广州市花都区花城市象贸易商行-滋柔' and deliver_name!='LEIKESAER INFORMATION SERVICE LIMITED'
sql=$@"select sum(quantity_purchase) as count,sum(quantity_purchase*unit_price) as amount,bailun_sku,warehouse_from_code as warehouse_code,warehouse_from_name as warehouse_name from dc_semi_purchase_info where detail_delstatus=0 and create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and `status`>-1 and deliver_name !='广州哈倪蔓生物科技有限公司' and deliver_name!='广州市花都区花城市象贸易商行-滋柔' and deliver_name!='LEIKESAER INFORMATION SERVICE LIMITED'
sql=$@"select sum(sku_quantity) as count,sum(sku_quantity*sku_unit_price) as amount,sku as bailun_sku,warehouse_id as warehouse_code,warehouse_name from dc_semi_order where state!=1 and create_date>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_date<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by sku,warehouse_id";
sql=$@"select sum(sku_quantity) as count,sum(sku_quantity*sku_unit_price) as amount,sku as bailun_sku,warehouse_id as warehouse_code,warehouse_name from dc_semi_order where state!=1 and create_date>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_date<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by sku,warehouse_id";
sql=$@"select t1.sku_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,t1.log_quantity as count,(t1.log_quantity*t2.price) amount from dc_semi_stock_log t1
sql=$@"select t1.sku_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,t1.log_quantity as count,(t1.log_quantity*t2.price) amount from dc_semi_stock_log t1
left join (select t1.sku_code,t1.price from dc_semi_supplier_offer_log t1
left join (select t1.sku_code,t1.price from dc_semi_supplier_offer_log t1
inner join (select sku_code,max(update_time) update_time from dc_semi_supplier_offer_log where sku_code in (select sku_code from dc_semi_stock_log where update_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and update_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and log_type_id=2) group by sku_code,update_time) t2 on t1.sku_code=t2.sku_code and t1.update_time=t2.update_time) t2 on t1.sku_code=t2.sku_code
inner join (select sku_code,max(update_time) update_time from dc_semi_supplier_offer_log where sku_code in (select sku_code from dc_semi_stock_log where update_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and update_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and log_type_id=2) group by sku_code,update_time) t2 on t1.sku_code=t2.sku_code and t1.update_time=t2.update_time) t2 on t1.sku_code=t2.sku_code
where t1.update_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.update_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and log_type_id=2";
where t1.update_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.update_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and log_type_id=2";
sql=$@"select t1.material_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,sum(t1.stock) as count,sum(t1.stock*t1.new_price) amount from dc_semi_stock_report t1
sql=$@"select t1.material_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,sum(t1.stock) as count,sum(t1.stock*t1.new_price) amount from dc_semi_stock_report t1
where t1.is_zichang=0 and t1.stock_type=3 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by t1.material_code,t1.warehouse_id;";
where t1.is_zichang=0 and t1.stock_type=3 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by t1.material_code,t1.warehouse_id;";
sql=$@"select t1.material_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,sum(t1.stock) as count,sum(t1.stock*t1.new_price) amount from dc_semi_stock_report t1
sql=$@"select t1.material_code as bailun_sku,t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,sum(t1.stock) as count,sum(t1.stock*t1.new_price) amount from dc_semi_stock_report t1
where t1.is_zichang=0 and t1.stock_type=5 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by t1.material_code,t1.warehouse_id;";
where t1.is_zichang=0 and t1.stock_type=5 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' group by t1.material_code,t1.warehouse_id;";
sql=$@"select t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,t1.sku_code as bailun_sku,t1.final_stock as usable_stock,(t1.final_stock*t2.price) as stockAmount from dc_semi_stock_log t1 join dc_semi_supplier_offer_log t2 on t1.sku_code=t2.sku_code where t1.sku_code='{item.bailun_sku}' and t1.warehouse_id='{item.warehouse_code}' order by t2.update_time desc";
sql=$@"select t1.warehouse_id as warehouse_code,t1.warehouse_name as warehouse_name,t1.sku_code as bailun_sku,t1.final_stock as usable_stock,(t1.final_stock*t2.price) as stockAmount from dc_semi_stock_log t1 join dc_semi_supplier_offer_log t2 on t1.sku_code=t2.sku_code where t1.sku_code='{item.bailun_sku}' and t1.warehouse_id='{item.warehouse_code}' order by t2.update_time desc";
sql=$@"select t1.warehouse_id warehouse_code,t1.warehouse_name,t1.sku_code bailun_sku,t1.stock_quantity usable_stock,(t1.stock_quantity*t1.price) as stockAmount from dc_semi_daily_stock t1 where t1.day='{start.AddDays(-1).ToString("yyyy-MM-dd")}' and t1.sku_code='{item.bailun_sku}' and t1.warehouse_id='{item.warehouse_code}'";
sql=$@"select t1.warehouse_id warehouse_code,t1.warehouse_name,t1.sku_code bailun_sku,t1.stock_quantity usable_stock,(t1.stock_quantity*t1.price) as stockAmount from dc_semi_daily_stock t1 where t1.day='{start.AddDays(-1).ToString("yyyy-MM-dd")}' and t1.sku_code='{item.bailun_sku}' and t1.warehouse_id='{item.warehouse_code}'";