Commit bdd5766b by 泽锋 李

采购建议被误移除

parent c2b88689
......@@ -541,10 +541,11 @@ and ( t5.`status`=0 or t5.`status` is null ) and t7.sum_quantity_init_advise>0
// 旧品30天内只有1单,不备货;新品只出过单则只出缺货
var datas1 = OldProductCalculation(datas3);
var test1 = datas1.FirstOrDefault(s=>s.bailun_sku_warehouse_code== "954268701GZBLWH");
//清理同区域冗余数量
var datas2 = AreaRedundancyClear(datas1);
if (datas2 != null && datas2.Count >= 1)
var test2 = datas2.FirstOrDefault(s => s.bailun_sku_warehouse_code == "954268701GZBLWH");
if (datas2 != null && datas2.Count >= 1)
{
if (is_clear_data)
......@@ -582,51 +583,55 @@ set t1.quantity_final_advise=GREATEST(0,t1.quantity_final_advise-t2.quantity_out
where t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code and t1.bailun_sku=t3.bailun_sku
and t1.quantity_init_advise>=0 and ( t3.buyer_name in ('张莹霞1') and t1.warehouse_code='GZBLWH' ) and t1.main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0);
// 调整因为舍弃小数导致的moq不足
var datas = MyMySqlConnection._connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0).AsList().ToList();
if (datas != null && datas.Count > 0)
//全量出的时候,才需要这一步
if (is_clear_data)
{
foreach (var itemGoods in datas.GroupBy(s => new { s.suppliers_id, s.product_inner_code, s.warehouse_code }))
// 调整因为舍弃小数导致的moq不足
var datas = MyMySqlConnection._connection.Query<dc_auto_purchase_advise_detailed>(" select * from dc_auto_purchase_advise_detailed where main_id=@main_id ", new { main_id = mainID }, commandTimeout: 0).AsList().ToList();
if (datas != null && datas.Count > 0)
{
// 判断总建议采购数是否达到了moq
var difference = itemGoods.Max(s => s.goods_moq) - itemGoods.Sum(s => s.quantity_final_advise);
if (difference > 0)
{
// 把最大的那条记录找出来,加给他
var max_data = itemGoods.OrderByDescending(s => s.history_fourteenday_sales).FirstOrDefault();
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new
{
quantity_final_advise = max_data.quantity_final_advise + difference,
id = max_data.id
});
}
else if (difference < 0)
foreach (var itemGoods in datas.GroupBy(s => new { s.suppliers_id, s.product_inner_code, s.warehouse_code }))
{
// 由于上面的补单规则,会导致超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减
var abatement = 0 - difference;
foreach (var item in itemGoods.Where(s => s.quantity_init_advise < 0).OrderBy(s => s.goods_history_fourteenday_sales))
// 判断总建议采购数是否达到了moq
var difference = itemGoods.Max(s => s.goods_moq) - itemGoods.Sum(s => s.quantity_final_advise);
if (difference > 0)
{
if (abatement >= item.quantity_final_advise)
// 把最大的那条记录找出来,加给他
var max_data = itemGoods.OrderByDescending(s => s.history_fourteenday_sales).FirstOrDefault();
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new
{
_connection.Execute(" delete from dc_auto_purchase_advise_detailed where id=@id ", new { id = item.id });
abatement -= item.quantity_final_advise;
}
else
quantity_final_advise = max_data.quantity_final_advise + difference,
id = max_data.id
});
}
else if (difference < 0)
{
// 由于上面的补单规则,会导致超出moq . 有超出的部分,把补单的(初始建议数为负数)按销量排序,逐个消减
var abatement = 0 - difference;
foreach (var item in itemGoods.Where(s => s.quantity_init_advise < 0).OrderBy(s => s.goods_history_fourteenday_sales))
{
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new { id = item.id, quantity_final_advise = item.quantity_final_advise - abatement });
abatement = 0;
}
if (abatement >= item.quantity_final_advise)
{
_connection.Execute(" delete from dc_auto_purchase_advise_detailed where id=@id ", new { id = item.id });
abatement -= item.quantity_final_advise;
}
else
{
_connection.Execute(" update dc_auto_purchase_advise_detailed set quantity_final_advise=@quantity_final_advise where id=@id ", new { id = item.id, quantity_final_advise = item.quantity_final_advise - abatement });
abatement = 0;
}
if (abatement <= 0)
{
break;
if (abatement <= 0)
{
break;
}
}
}
}
}
}
//ImportShoujiShortageDetailed(mainID);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment