item.purchase_advise_count=_connection.QuerySingleOrDefault<int>(" select count(1) from dc_auto_purchase_advise_detailed where warehouse_code=@warehouse_code and bailun_sku=@bailun_sku ",new{item.warehouse_code,item.bailun_sku});
foreach(variteminobj)
{
item.purchase_advise_count=_connection.QuerySingleOrDefault<int>(" select count(1) from dc_auto_purchase_advise_detailed where warehouse_code=@warehouse_code and bailun_sku=@bailun_sku ",new{item.warehouse_code,item.bailun_sku});
and t2.buyer_name in ('赵美聪','张莹霞','张莹霞1') and ( t1.quantity_inventory + t1.quantity_transfer + t1.quantity_purchase < t1.quantity_out_stock ) ",commandTimeout:0);
// 把 在库+在途>缺货的改成0
_connection.Execute(@" update
dc_auto_turnover as t1,
dc_base_sku as t2
set t1.quantity_init_advise=0
where t1.bailun_sku = t2.bailun_sku
and t2.buyer_name in ('赵美聪','张莹霞','张莹霞1') and ( t1.quantity_inventory + t1.quantity_transfer + t1.quantity_purchase >= t1.quantity_out_stock ) ",commandTimeout:0);
// 生成采购建议
// 生成采购建议 (只补缺货的不管)
_connection.Execute(@"
INSERT into dc_auto_purchase_advise_detailed(`bailun_sku`,`warehouse_code`,`quantity_init_advise`,`quantity_final_advise`,
left join dc_auto_config_sku_warehouse as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_base_sku as t6 on t1.bailun_sku = t6.bailun_sku
left join view_goods_moq as t7 on t6.product_inner_code = t7.product_inner_code and t1.warehouse_code = t7.warehouse_code and t6.suppliers_id = t7.suppliers_id
where (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 ) and ( t5.`status`=0 or t5.`status` is null ) and t7.sum_quantity_init_advise>0
where (t1.history_fourteenday_sales>0 or t1.quantity_out_stock>0 ) and ( t5.`status`=0 or t5.`status` is null ) and t7.sum_quantity_init_advise>0 and t6.buyer_name not in ('赵美聪','张莹霞','张莹霞1')
) as t1 where t1.quantity_final_advise>0
)
",new{main_id=mainID},commandTimeout:0);
// 采购员为 赵美聪 的商品 按缺货数量下单
_connection.Execute(@" INSERT into dc_auto_purchase_advise_detailed(`bailun_sku`,`warehouse_code`,`quantity_init_advise`,`quantity_final_advise`,
t1.quantity_init_advise as 'quantity_init_advise', -- 原始采购建议数量 new
( t1.quantity_out_stock - ( t1.quantity_inventory + t1.quantity_transfer + t1.quantity_purchase ) ) as 'quantity_final_advise', -- 计算moq之后的数量 new
t6.product_inner_code as 'product_inner_code', -- 内部商品编码 new
0 as 'goods_quantity_init_advise', -- 商品本次的建议下单数量 new
0 as 'goods_moq', -- 商品的moq new
0 as 'good_sku_codes', -- 商品涉及的下单所有sku new
0 as 'goods_history_fourteenday_sales', -- 商品的最近14日总日均销量
t1.history_fourteenday_sales as 'history_fourteenday_sales', -- sku的最近14日日均
0 as 'quantity_actual', -- 真实下单数量
@main_id as 'main_id',
t2.forecast_formula as 'forecast_formula',
t2.fit_forecast_formula as 'fit_forecast_formula',
t1.turnover_days,
t1.supplier_delivery,
t1.inspection_delivery,
t1.transfer_delivery,
t1.sales_upper_limit,
0 as 'ispush',
1 as 'type',
t6.suppliers_id
from dc_auto_turnover as t1
left join dc_auto_sales as t2 on t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
left join dc_auto_config_sku_warehouse as t5 on t1.bailun_sku = t5.bailun_sku and t1.warehouse_code = t5.warehouse_code
left join dc_base_sku as t6 on t1.bailun_sku = t6.bailun_sku
where t6.buyer_name in ('赵美聪','张莹霞','张莹霞1') and ( t1.quantity_inventory + t1.quantity_transfer + t1.quantity_purchase < t1.quantity_out_stock )
) ",new{main_id=mainID});
// 凑单sku(初始建议数没有) 如果下单数只有一个,改为2
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=2 where quantity_final_advise=1 and quantity_init_advise<=0 and main_id=@main_id ",new{main_id=mainID});
// 初始建议数为1,,系统建议数为1时 改为3
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=3 where quantity_final_advise=1 and quantity_init_advise=1 and main_id=@main_id ",new{main_id=mainID});
// 凑单sku(初始建议数没有) 如果下单数只有一个,改为2 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set t1.quantity_final_advise=2
where t1.quantity_final_advise=1 and t1.quantity_init_advise<=0 and t2.buyer_name not in ('赵美聪','张莹霞','张莹霞1') and t1.main_id=@main_id ",new{main_id=mainID});
// 初始建议数为1,,系统建议数为1时 改为3 ( 只补缺货的不管 )
_connection.Execute(@" update dc_auto_purchase_advise_detailed as t1,
dc_base_sku as t2
set quantity_final_advise=3
where quantity_final_advise=1 and quantity_init_advise=1 and t2.buyer_name not in ('赵美聪','张莹霞','张莹霞1') and main_id=@main_id ",new{main_id=mainID});
// 调整因为舍弃小数导致的moq不足
vardatas=_connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ",new{main_id=mainID}).AsList();
...
...
@@ -274,7 +303,8 @@ t1.*,t2.warehouse_name,t3.sku_title_cn as 'sku_name',t4.create_time,t3.buyer_nam
(t5.quantity_purchase) as 'quantity_purchase', -- 采购在途
(t5.quantity_inventory) as 'quantity_inventory', -- 库存数
(t3.unit_price * (case when t1.quantity_actual>0 then t1.quantity_actual else t1.quantity_final_advise end ) ) as 'quantity_final_advise_price', -- 采购金额
t3.suppliers_name
t3.suppliers_name,
(t1.history_fourteenday_sales - t5.forecast_fourteenday_sales) as 'sudden_increase' -- 突增关注
from dc_auto_purchase_advise_detailed as t1
left join dc_base_warehouse as t2 on t1.warehouse_code = t2.warehouse_code
left join dc_base_sku as t3 on t1.bailun_sku = t3.bailun_sku
...
...
@@ -283,7 +313,6 @@ left join dc_auto_turnover as t5 on t1.warehouse_code = t5.warehouse_code and t1